-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerator-code.py
More file actions
188 lines (186 loc) · 6.39 KB
/
Copy pathgenerator-code.py
File metadata and controls
188 lines (186 loc) · 6.39 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import random
import string
def generator(length,al_len,num_ch,spec_ch):
if (num_ch==False and spec_ch==False):
str_l=string.ascii_letters
else:
str_l=[string.ascii_letters]
if num_ch==True:
str_l+=[string.digits]
if spec_ch==True:
str_l+=['!@#$%^&*{()[]}~?/|><:;_-+=']
password=random.choice(str_l[0])
if (num_ch==False and spec_ch==False):
for i in range(length-1):
password+=random.choice(str_l)
else:
acount,ncount,scount=0,0,0
for i in range(length-1):
s=random.choice(str_l)
password+=random.choice(s)
if s.isalpha():
acount+=1
elif s.isdigit():
ncount+=1
else:
scount+=1
while True:
if acount<al_len:
n=al_len-acount
c=0
password=list(password)
while n!=c:
x=random.choice(password)
if x.isalpha():
None
else:
if x.isdigit():
ncount-=1
else:
scount-=1
for i in range(len(password)):
if password[i]==x:
password[i]=random.choice(string.ascii_letters)
acount+=1
c+=1
break
password=''.join(password)
elif (num_ch==True and ncount==0):
y=random.choice(password)
if y.isalpha():
acount-=1
else:
scount-=1
password=list(password)
for i in range(len(password)):
if y==password[i]:
password[i]=random.choice(string.digits)
ncount+=1
break
password=''.join(password)
elif (spec_ch==True and scount==0):
z=random.choice(password)
if z.isalpha():
acount-=1
else:
ncount-=1
password=list(password)
for i in range(len(password)):
if z==password[i]:
password[i]=random.choice('!@#$%^&*{()[]}~?/|><:;_-+=')
scount+=1
break
password=''.join(password)
else:
break
return password
#main program
print("------------------------------------------------------------")
print()
print(" PASSWORD GENERATOR")
print()
print("------------------------------------------------------------")
while True:
try:
l=int(input("Enter the length of the password: "))
except ValueError:
print("Invalid Input")
print("-----------------------------------")
else:
break
while True:
ch1=input("Include numbers?(yes/no) ").lower()
if ch1=='yes':
ch1=True
break
elif ch1=='no':
ch1=False
break
else:
print("Invalid Input")
print("-----------------------------------")
while True:
ch2=input("Include special characters?(yes/no) ").lower()
if ch2=='yes':
ch2=True
break
elif ch2=='no':
ch2=False
break
else:
print("Invalid Input")
print("-----------------------------------")
while True:
while True:
try:
min_al=int(input("Enter the minimum number of alpabets required in the password: "))
except ValueError:
print("Invalid Input")
print("-----------------------------------")
else:
break
flag=0
if (min_al>l-2 and ch1==ch2==True):
print(f"The minimum number of alphabets can't be {min_al} because there needs to atleast one special character and one number.")
print("-----------------------------------")
flag=1
elif min_al>l-1:
if flag!=1:
if ch1==True:
print(f"The minimum number of alphabets can't be {min_al} because there needs to atleast one number.")
print("-----------------------------------")
flag=1
elif ch2==True:
print(f"The minimum number of alphabets can't be {min_al} because there needs to atleast one special character.")
print("-----------------------------------")
flag=1
if flag==1:
print("Please change either...")
print("1. The length of the password\n2. The minimum number of alphabets")
while True:
try:
ch=int(input("Enter 1/2: "))
print("-----------------------------------")
except ValueError:
print("Invalid Input")
else:
if ch==1:
print("Enter the new length...")
while True:
try:
l2=int(input())
except ValueError:
print("Invalid Input")
print("-----------------------------------")
else:
if l2<=l:
print(f"Please enter a length greater than the previous one({l})")
else:
l=l2
break
elif ch==2:
break
else:
print("Invalid Input")
print("-----------------------------------")
else:
print("-----------------------------------")
break
print("All inputs valid!")
print("-----------------------------------")
while True:
print("Generated Password: ",generator(l,min_al,ch1,ch2))
print("-----------------------------------")
while True:
regen=input("Regenerate?(yes/no) ").lower()
if (regen=='yes' or regen=='no'):
break
else:
print("Invalid Input")
print("-----------------------------------")
if regen=='yes':
print("-----------------------------------")
continue
else:
print("-----------------------------------")
break