Created
May 8, 2011 22:05
-
-
Save EntityReborn/961725 to your computer and use it in GitHub Desktop.
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
import hashlib | |
class User(object): | |
def __init__(self): | |
self.password = "" | |
def set_password(self, raw_password): | |
hash = "pass" # randomly generate this | |
m = hashlib.sha1(raw_password + hash) | |
self.password = "%s$%s" % (m.hexdigest(), hash) | |
def check_password(self, raw_password): | |
if not "$" in self.password: | |
return False | |
pass_, hash = self.password.split("$") | |
m = hashlib.sha1(raw_password + hash) | |
return m.hexdigest() == pass_ | |
u = User() | |
u.set_password("ohai") | |
print u.check_password("ohai") | |
print u.check_password("ohai2") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment