Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate the fact that passwords are saved as hashes in user model. #85

Open
Askir opened this issue Mar 17, 2019 · 0 comments
Open

Comments

@Askir
Copy link
Collaborator

Askir commented Mar 17, 2019

Currently the user model has a property password and every line that saves a new password has to manually hash it. The method update somewhat encapsulates this already.

A nice way to do this imo, would be to rename the property to _password_digest (making in private) and adding accessors with @property and @setter to password which encapsulate the hashing.
This way a new password can be saved like this:

if user.check_password(old_password):
  user.password = new_password

and it will still be hashed.
user.update(password=new_password) will also work without overriding the update method then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant