Skip to content

Instantly share code, notes, and snippets.

@EntityReborn
Created May 8, 2011 22:05
Show Gist options
  • Save EntityReborn/961725 to your computer and use it in GitHub Desktop.
Save EntityReborn/961725 to your computer and use it in GitHub Desktop.
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