Created
July 15, 2015 05:47
-
-
Save dmendiza/9a7269d5c521e72cc221 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add new import | |
from sqlalchemy_utils.types.password import PasswordType | |
# Change password in User model | |
password = db.Column(PasswordType( | |
schemes=[ | |
'bcrypt', | |
'plaintext' | |
], | |
deprecated=['plaintext'], | |
max_length=40 | |
)) | |
# Change user query | |
query = User.query.filter_by(username=username) | |
# Add _verify_password function | |
def _verify_password(db_user, password): | |
if db_user.password == password: | |
# ideally we don't save this unless it has changed | |
db.session.add(db_user) | |
db.session.commit() | |
return True | |
else: | |
return False | |
# Use _verify_password | |
if not db_user or not _verify_password(db_user, password): |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment