def generate_password consonants vowels replacements have_no_digit Tru

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def generate_password():
consonants = ('b', 'd', 'g', 'h', 'k', 'l', 'm', 'n', 'p', 'r', 's', 't', 'z')
vowels = ('a', 'e', 'i', 'o', 'u')
replacements = {
'o': '0',
'i': '1',
'e': '3',
'a': '4',
't': '7',
'q': '9',
'g': '9',
}
have_no_digit = True
have_no_upper = True
password = []
# length of password is 8 symbols
for i in xrange(4):
password.append(random.choice(consonants))
password.append(random.choice(vowels))
while have_no_digit or have_no_upper:
if have_no_digit:
symb = random.choice(password)
if symb in replacements:
password[password.index(symb)] = replacements[symb]
have_no_digit = False
if have_no_upper:
symb = random.choice(password)
if symb.isalpha():
password[password.index(symb)] = symb.upper()
have_no_upper = False
return ''.join(password)