-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.py
174 lines (161 loc) · 6.16 KB
/
password_generator.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
from random import randint
import random
def main():
alphabet_list = alphabet()
symbols_list = symbols()
ch1, ch2, ch3 = choices()
proceed, ch2_proceed, ch3_proceed = check(ch2, ch3)
generation(alphabet_list, symbols_list, proceed, ch2_proceed, ch3_proceed, ch1)
def generation(alphabet_list, symbols_list, proceed, ch2_proceed, ch3_proceed, ch1):
password = ''
for i in range(ch1):
#Checking the choices that are True
if proceed == 0:
random_selection = 1
elif proceed == 1 and ch2_proceed:
random_selection = randint(1, 2)
else:
if ch2_proceed:
random_selection = randint(1, 3)
else:
random_selection = random.choice([1, 3])
#Creating the password by the random_selection values
if random_selection == 1:
password = password + str(randint(0, 9))
elif random_selection == 2 and ch2_proceed == True:
lower_lt = randint(0, 1)
if lower_lt == 1:
alph_index = randint(0, len(alphabet_list)-1)
password = password + alphabet_list[alph_index].lower()
else:
alph_index = randint(0, len(alphabet_list)-1)
password = password + alphabet_list[alph_index]
elif random_selection == 3 and ch3_proceed == True:
symp_index = randint(0, len(symbols_list)-1)
password = password + symbols_list[symp_index]
lower_letters = 0
upper_letters = 0
symb_chars = 0
cont_loop = False
for i in password:
try:
if type(int(password)) != int:
if i.islower():
lower_letters += 1
if i.isupper():
upper_letters += 1
if i in symbols_list:
symb_chars += 1
except Exception:
if i.islower():
lower_letters += 1
if i.isupper():
upper_letters += 1
if i in symbols_list:
symb_chars += 1
try:
if type(int(password)) != int:
if ch2_proceed:
if lower_letters == 0 or upper_letters == 0:
password = ''
lower_letters = 0
upper_letters = 0
symb_chars = 0
cont_loop = True
else:
cont_loop = False
except Exception:
cont_loop = False
#If the "For" loop give cont_loop = True the script will continue with the "while" loop
while cont_loop:
for i in range(ch1):
#Checking the choices that are True
if proceed == 0:
random_selection = 1
elif proceed == 1 and ch2_proceed:
random_selection = randint(1, 2)
else:
if ch2_proceed:
random_selection = randint(1, 3)
else:
random_selection = random.choice([1, 3])
#Creating the password by the random_selection values
if random_selection == 1:
password = password + str(randint(0, 9))
elif random_selection == 2 and ch2_proceed == True:
lower_lt = randint(0, 1)
if lower_lt == 1:
alph_index = randint(0, len(alphabet_list)-1)
password = password + alphabet_list[alph_index].lower()
else:
alph_index = randint(0, len(alphabet_list)-1)
password = password + alphabet_list[alph_index]
elif random_selection == 3 and ch3_proceed == True:
symp_index = randint(0, len(symbols_list)-1)
password = password + symbols_list[symp_index]
for i in password:
try:
if type(int(password)) != int:
if i.islower():
lower_letters += 1
if i.isupper():
upper_letters += 1
if i in symbols_list:
symb_chars += 1
except Exception:
if i.islower():
lower_letters += 1
if i.isupper():
upper_letters += 1
if i in symbols_list:
symb_chars += 1
try:
if type(int(password)) != int:
if ch2_proceed:
if lower_letters == 0 or upper_letters == 0:
password = ''
lower_letters = 0
upper_letters = 0
symb_chars = 0
cont_loop = True
else:
cont_loop = False
except Exception:
cont_loop = False
print(password)
def check(ch2, ch3):
ch2_proceed = False
ch3_proceed = False
proceed = 0
if ch2 == 1:
ch2_proceed = True
proceed += 1
if ch3 == 2:
ch3_proceed = True
proceed += 1
return proceed, ch2_proceed, ch3_proceed
def choices():
choice1 = int(input('How big do you want your password to be: '))
print('')
choice2 = int(input('Do you want your password to contain letter? If yes give --> 1 else give 0: '))
print('')
while choice2 > 1 or choice2 < 0:
print('Wrong input. Please try again.')
choice2 = int(input('Do you want your password to contain letter? If yes give --> 1 else give 0: '))
print('')
choice3 = int(input('Do you want your password to contain symbols? If yes give --> 2 else give 0: '))
print('')
while choice3 > 2 or choice2 < 0:
print('Wrong input. Please try again.')
choice2 = int(input('Do you want your password to contain symbols? If yes give --> 2 else give 0: '))
print('')
return choice1, choice2, choice3
def alphabet():
alphabet_list = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z']
return alphabet_list
def symbols():
symp = ['!', '@', '#', '$', '%', '*', '^', '&', '/']
return symp
main()