-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.py
94 lines (55 loc) · 2.54 KB
/
project.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
import random
def main():
print("============================================================INDIAN PASSWORD GENERATOR======================================================================")
print("==============================================================BY SOHAM SAHA=========================================================================")
numPasswords = int(input("How many passwords do you want to generate? "))
print("Generating " +str(numPasswords)+" passwords")
passwordLengths = []
print("Minimum length of password should be 8")
for i in range(numPasswords):
length = int(input("Enter the length of Password #" + str(i+1) + " "))
new_length = length_checker(length)
passwordLengths.append(new_length)
Password = generatePassword(passwordLengths)
for i in range(numPasswords):
print ("Password #"+str(i+1)+" = " + Password[i])
def length_checker(length):
if length<8:
length = 8
return length
def generatePassword(pwlength):
alphabet = "abcdefghijklmnopqrstuvwxyz"
passwords = []
for i in pwlength:
password = ""
for j in range(i):
next_letter_index = random.randrange(len(alphabet))
password = password + alphabet[next_letter_index]
#print("PW:",password)
for j in range(i//4):
password = replaceWithNumber(password)
for k in range(j//3):
password = replaceWithSpecialChar(password)
password = replaceWithUppercaseLetter(password)
passwords.append(password)
return passwords
def replaceWithNumber(pword):
for i in range(random.randrange(1,8)):
replace_index = random.randrange(len(pword)//2)
pword = pword[0:replace_index] + str(random.randrange(10)) + pword[replace_index+1:]
#print("RWN:",pword)
return pword
def replaceWithUppercaseLetter(pword):
for i in range(random.randrange(1,8)):
replace_index = random.randrange(len(pword)//2,len(pword))
pword = pword[0:replace_index] + pword[replace_index].upper() + pword[replace_index+1:]
#print("RWUC:",pword)
return pword
def replaceWithSpecialChar(pword):
sp_char = ["@","!","#","$","%","^","&","*","_","-",".","?","=",":",";","/","(",")"]
for i in range(random.randrange(1,8)):
replace_index = random.randrange(len(pword)//2)
pword = pword[0:replace_index] + str(random.choice(sp_char)) + pword[replace_index+1:]
return pword
if __name__ == "__main__":
main()