Skip to content

Instantly share code, notes, and snippets.

@Julian-Nash
Last active August 19, 2021 21:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Julian-Nash/494053c8a82f23784d0a9124b2cdd049 to your computer and use it in GitHub Desktop.
Save Julian-Nash/494053c8a82f23784d0a9124b2cdd049 to your computer and use it in GitHub Desktop.
Query MongoDB for account (Mongoengine) / Bcrypt password hashing / Hashed password validation
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