Skip to content

Instantly share code, notes, and snippets.

@jasonwyatt
Created January 10, 2013 01:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonwyatt/4498635 to your computer and use it in GitHub Desktop.
Save jasonwyatt/4498635 to your computer and use it in GitHub Desktop.
Functions for hashing passwords, generating salts, and testing input passwords.
import base64
import uuid
import hashlib
def hash_password(password, salt=None):
if salt is None:
salt = uuid.uuid4().hex
hashed_password = hashlib.sha512(password + salt).hexdigest()
return (hashed_password, salt)
def verify_password(password, hashed_password, salt):
re_hashed, salt = hash_password(password, salt)
return re_hashed == hashed_password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment