Created
November 16, 2013 19:19
-
-
Save mrnejc/7504118 to your computer and use it in GitHub Desktop.
python - create password hash / test password against hash
This file contains 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
import uuid | |
import hashlib | |
def hash_password(password, version=1, salt=None): | |
if version == 1: | |
if salt == None: | |
salt = uuid.uuid4().hex[:16] | |
hashed = salt + hashlib.sha1( salt + password).hexdigest() | |
# generated hash is 56 chars long | |
return hashed | |
# incorrect version ? | |
return None | |
def test_password(password, hashed, version=1): | |
if version == 1: | |
salt = hashed[:16] | |
rehashed = hash_password(password, version, salt) | |
return rehashed == hashed | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment