[Tutor] Simple password generation
Trey Beck
list at ohtogo.com
Tue May 24 01:05:49 CEST 2005
Hi. First post.
I'm trying to (more or less) copy the functionality of quepasa
(http://quepasa.sourceforge.net), a simple password generation script
that builds passwords from a combination of a passphrase and another
string (like a domain name).
If you enter the same passphrase and string, you should get the same
password (in case you forget...).
I've added a bit so that if neither a passphrase nor a string is
entered, the function returns a random (or somewhat random) eight-
character string.
Am i on the right track here? (I'm brand new to sha and so forth.)
Criticisms?
Thx!
Trey
---
import sha, re, base64, string
from random import choice
def QuePasa (salt='', passphrase='', length=8):
salted = passphrase + salt
newpasswd = ''
if (salted):
hash = sha.new(salted).digest()
# for now, strip non-alphanumeric characters
newpasswd = re.sub(r'\W', '', base64.encodestring(hash))
[:length]
else:
chars = string.letters + string.digits
for i in range(length):
newpasswd = newpasswd + choice(chars)
return newpasswd
if __name__ == "__main__":
sites = ['thissite.com','thatsite.com', 'theothersite.com','']
passphrase = 'all your base are belong to us'
for i in range(10):
for site in sites:
print "%s : %s" % (site, QuePasa(passphrase, site))
More information about the Tutor
mailing list