-
Notifications
You must be signed in to change notification settings - Fork 0
/
Passwd-Generator_v4--Choice of any character.py
72 lines (59 loc) · 1.95 KB
/
Passwd-Generator_v4--Choice of any character.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
import secrets
import string
import random
# characters to generate password from
letters = list(string.ascii_letters)
numbers = list(string.digits)
special_characters = list("!@#$%^&*" + "()")
def generate_random_password():
# amount of letters in password with input validation
while True:
try:
letter_count = int(input("Enter the desired amount of letters: "))
except ValueError:
print("Please use numbers only. No spaces, no special characters- just numbers.")
continue
else:
break
# amount of numbers in password
while True:
try:
number_count= int(input("Enter the desired amount of numbers: "))
except ValueError:
print("Please use numbers only. No spaces, no special characters- just numbers.")
continue
else:
break
# amount of special characters in password
while True:
try:
spec_char_count = int(input("Enter the desired amount of characters: "))
except ValueError:
print("Please use numbers only. No spaces, no special characters- just numbers.")
continue
else:
break
# picking random characters from the list
password = []
for i in range(letter_count):
password.append(secrets.choice(letters))
for i in range(number_count):
password.append(secrets.choice(numbers))
for i in range(spec_char_count):
password.append(secrets.choice(special_characters))
# shuffling the resultant password
random.shuffle(password)
# printing the list
print("".join(password))
length = str(letter_count + number_count + spec_char_count)
print("Your password is " + length + " characters long.")
## invoking the function with error handling
generate_random_password()
""" Accredited links:
Input validation and loop:
https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response
Entropy:
https://docs.python.org/3/library/secrets.html
Password generator base idea:
https://gist.github.com/23maverick23/4131896
"""