-
Notifications
You must be signed in to change notification settings - Fork 0
/
strong_passgen_for_prod.py
53 lines (43 loc) · 1.32 KB
/
strong_passgen_for_prod.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
# import modules
import string
import random
# store all characters in lists
s1 = list(string.ascii_lowercase)
s2 = list(string.ascii_uppercase)
s3 = list(string.digits)
s4 = list(string.punctuation)
# Ask user about the number of characters
user_input = input("How many characters do you want in your password? ")
# check this input is it number? is it more than 8?
while True:
try:
characters_number = int(user_input)
if characters_number < 8:
print("Your password must be at least 8 characters long")
user_input = input("Please, Enter your number again: ")
else:
break
except:
print("Please, Enter a number")
user_input = input("Please, Enter your number again: ")
# shuffle all lists
random.shuffle(s1)
random.shuffle(s2)
random.shuffle(s3)
random.shuffle(s4)
# calculate 30% & 20% of number of characters
part1 = round(characters_number * (30 / 100))
part2 = round(characters_number * (20 / 100))
# generation of the password (60% letters and 40% digits & punctuations)
result = []
for x in range(part1):
result.append(s1[x])
result.append(s2[x])
for x in range(part2):
result.append(s3[x])
result.append(s4[x])
# shuffle the result
random.shuffle(result)
# join the result
password = "".join(result)
print("Strong Password: ", password)