|
Description:
Password will be generated in the form 'word'+digits+'word' eg.,nice137pace
instead of a difficult-to-remember - K8Yn9muL
Source: Text Source
def nicepass(alpha=6,numeric=2):
"""
returns a human-readble password (say rol86din instead of
a difficult to remember K8Yn9muL )
"""
import string
import random
vowels = ['a','e','i','o','u']
consonants = [a for a in string.ascii_lowercase if a not in vowels]
digits = string.digits
def a_part(slen):
ret = ''
for i in range(slen):
if i%2 ==0:
randid = random.randint(0,20)
ret += consonants[randid]
else:
randid = random.randint(0,4)
ret += vowels[randid]
return ret
def n_part(slen):
ret = ''
for i in range(slen):
randid = random.randint(0,9)
ret += digits[randid]
return ret
fpl = alpha/2
if alpha % 2 :
fpl = int(alpha/2) + 1
lpl = alpha - fpl
start = a_part(fpl)
mid = n_part(numeric)
end = a_part(lpl)
return "%s%s%s" % (start,mid,end)
if __name__ == "__main__":
print nicepass(6,2)
Discussion:
Other receipies like:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/59873 generate a strong albeit difficult to remember password.
This script will be useful in cases where you are sending auto-generated passwords to registrants(say) over email.
This password is difficult than a dictionary word, at the same time easy enough to 'read' and remember by the recipient.
|