-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordGenerate.py
More file actions
95 lines (76 loc) · 2.34 KB
/
PasswordGenerate.py
File metadata and controls
95 lines (76 loc) · 2.34 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
from random import randint
def isNumber (x):
val = 0
try:
x = int(x)
except ValueError:
val = False
else:
val = True
return val
def shuffle(x):
y = []
for i in range(len(x)):
if i < len(x)-1:
k = randint(0,(len(x)-1)-i)
else:
k = 0
y.append(x[k])
x.remove(x[k])
return ''.join(y)
print("\n\tWelcome to the password generator!\n")
print("Please note that the minimum size for a password using this generator is 8 characters.")
L = input("Please enter the desired length of your password: ")
while ((isNumber(L) and int(L) < 8) or not isNumber(L)):
print("Your desired password length must be an integer greater than or equal to 8.")
L = input("Please enter the desired length of your password: ")
L = int(L)
print("Now choose one of the following options:")
print("0: alphanumeric | 1: alphanumeric and special characters")
choice = input("Please enter your choice: ")
while (choice != str(0) and choice != str(1)):
print("Please make sure you make a valid choice. The options are '0' or '1'.")
choice = input("Please enter your choice: ")
choice = int(choice)
if (not choice):
numberCount = randint(1,L//2+1)
alphaCount = randint(1,L-(numberCount+1))
alphaCapCount = L - (numberCount+alphaCount)
number = []
alpha = []
alphaCap = []
for i in range(numberCount):
number.append(randint(0,9))
for i in range(alphaCount):
alpha.append(randint(97,122))
for i in range(alphaCapCount):
alphaCap.append(randint(65,90))
number = list(map(str,number))
alpha = list(map(chr,alpha))
alphaCap = list(map(chr,alphaCap))
temp = number+alpha+alphaCap
else:
numberCount = randint(1,L//2+1)
alphaCount = randint(1,L-(numberCount+2))
alphaCapCount = randint(1,L-(numberCount+alphaCount+1))
specialCount = L - (numberCount+alphaCount+alphaCapCount)
number = []
alpha = []
alphaCap = []
special = []
specialSymbols = [33, 38, 40, 41, 46]
for i in range(numberCount):
number.append(randint(0,9))
for i in range(alphaCount):
alpha.append(randint(97,122))
for i in range(alphaCapCount):
alphaCap.append(randint(65,90))
for i in range(specialCount):
special.append(specialSymbols[randint(0,4)])
number = list(map(str,number))
alpha = list(map(chr,alpha))
alphaCap = list(map(chr,alphaCap))
special = list(map(chr,special))
temp = number+alpha+alphaCap+special
password = shuffle(temp)
print("\n\tYour password is: "+password)