Skip to content

Instantly share code, notes, and snippets.

@irneh
Created May 3, 2013 20:52
Show Gist options
  • Save irneh/5514027 to your computer and use it in GitHub Desktop.
Save irneh/5514027 to your computer and use it in GitHub Desktop.
def randstr(length):
return ''.join(chr(random.randint(0,255)) for i in range(length))
def hash_password(password, maxtime=0.5, datalength=64):
return scrypt.encrypt(randstr(datalength), password, maxtime=maxtime)
def verify_password(hashed_password, guessed_password, maxtime=0.5):
try:
scrypt.decrypt(hashed_password, guessed_password, maxtime)
return True
except scrypt.error:
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment