Generating passwords, a quick Python snippet Wednesday, April 9, 2008

Generating a password in Python:

import md5, base64, random
random.seed()
s = raw_input("Enter salt: ")
print base64.b64encode(md5.md5(`random.random()` + s).digest())[:-2]

Works for me.

Of course, it's basically impossible to remember the password generated. And it is non-deterministic thanks to the random() call. And some braindead authentication systems don't like you having a number for the first character of the password, which this sometimes generates.

0 comments: