Skip to content

Instantly share code, notes, and snippets.

@pcote
Created September 26, 2016 13:50
Show Gist options
  • Save pcote/6674d5627798ef45de17e2072b8d7629 to your computer and use it in GitHub Desktop.
Save pcote/6674d5627798ef45de17e2072b8d7629 to your computer and use it in GitHub Desktop.
import hashlib
def is_password_valid(uname, pw, prehashed=False):
if prehashed:
password_arg = pw
else:
hasher = hashlib.sha1()
hasher.update(pw.encode())
password_arg = hasher.hexdigest()
user = get_user(uname)
if user and user.password == password_arg:
return True
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment