so I'm running a flask python app on dotcloud, and I'm basically trying to hash a password (using hashlib.sha512; the salt is uuid.uuid4().bytes).
user_dict['salt'] = uuid.uuid4().bytes
print_stderr(user_dict['salt'])
print_stderr(hashlib.sha512(user_dict['pwd'] + user_dict['salt']))
user_dict['pwd'] = hashlib.sha512(user_dict['pwd'] + user_dict['salt']).digest()
print_stderr(user_dict['pwd'])
This all works fine even in a python interpreter on dotcloud, but when I actually run the code on the server, it crashes (or something, the client gets a HTTP 500 code, but dotcloud logs just closes).
I can tell by which print
statements are executed and which are not, that it crashes on the uuid.uuid4().bytes
line. But if I replace that with a constant (e.g. "uehg83yydh") it doesn't fail immediately, rather on the hashlib.sha512(...).digest()
line.
You may also notice that print_stderr
is not a standard python function. It's a hack I am using to get dotcloud to print stuff from python (it prints to stderr instead of stdout). Surely there's a better way to debug on dotcloud that I'm not aware of?
Try this for your code.
Code:
>>> user_dict['salt'] = uuid.uuid4().hex
>>> print_stderr(user_dict['salt'])
>>> import hashlib
>>> m = hashlib.sha512()
>>> m.update(user_dict['pwd'])
>>> m.update(user_dict['salt'])
>>> user_dict['pwd'] = m.hexdigest()
>>> print_stderr(user_dict['pwd'])