Last active
August 19, 2021 21:50
-
-
Save Julian-Nash/494053c8a82f23784d0a9124b2cdd049 to your computer and use it in GitHub Desktop.
Query MongoDB for account (Mongoengine) / Bcrypt password hashing / Hashed password validation
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
def has_account(email): | |
email = email.strip() | |
user_query = User.objects(email=email) | |
status = False | |
for user in user_query: | |
if user.email == email: | |
status = True | |
else: | |
status = False | |
return status | |
def hash_password(password): | |
salt = bcrypt.gensalt() | |
return bcrypt.hashpw(password, salt) | |
def check_password(email, password): | |
match = False | |
password = password.encode("utf-8") | |
user = User.objects(email=email.strip()) | |
for field in user: | |
if bcrypt.hashpw(password, field.password) == field.password: | |
match = True | |
else: | |
match = False | |
return match |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment