2 ms·
I don't know of any pure-Python bcrypt implementation, but App Engine will let you calculate SHA-1 hashes with the built-in hashlib module. To make this slow en
by pjscott 16y ago
I don't know of any pure-Python bcrypt implementation, but App Engine will let you calculate SHA-1 hashes with the built-in hashlib module. To make this slow enough, you'll need to iterate it a bunch of times (at least 1000 is the usual recommendation). Something like this:
import hashlib
def slow_hash(password, salt, iterations=2000):
h = hashlib.sha1()
h.update(password)
h.update(salt)
for x in range(iterations):
h.update(h.digest())
return h.digest()
I haven't tested this code, but hopefully it illustrates the general idea. Repeatedly run the hash function on the output of the previous iteration. You may need to bump up the number of iterations later as computers get faster. It's not as good as bcrypt, but it also doesn't suck, and it should run just fine on App Engine.