-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpassword_generator.py
More file actions
47 lines (33 loc) · 1.64 KB
/
Copy pathpassword_generator.py
File metadata and controls
47 lines (33 loc) · 1.64 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
#program to generate a random password based on user_specified criteria
import random
ascii_characters = [chr(i) for i in range(128)]
upper_case_letters = ascii_characters[65:91]
numbers = ascii_characters[48:58]
special_chars = ascii_characters[33:48] + ascii_characters[58:65]
def questions():
length = int(input("Enter password length: "))
upper_choice = input("Include uppercase letter? (y/n): ")
nums_choice = input("Include numbers? (y/n): ")
special_choice = input("Include special characters? (y/n): ")
return length, upper_choice, nums_choice, special_choice
user_choices = questions()
length = user_choices[0]
final_list = ascii_characters[97:123]
if user_choices[1]=='y' and user_choices[2] == 'y' and user_choices[3] == 'y':
final_list += upper_case_letters + numbers + special_chars
elif user_choices[1]=='y' and user_choices[2] == 'y' and user_choices[3] == 'n':
final_list += upper_case_letters + numbers
elif user_choices[1]=='y' and user_choices[2] == 'n' and user_choices[3] == 'n':
final_list += upper_case_letters
elif user_choices[1]=='n' and user_choices[2] == 'n' and user_choices[3] == 'n':
final_list = final_list
elif user_choices[1]=='n' and user_choices[2] == 'n' and user_choices[3] == 'y':
final_list += special_chars
elif user_choices[1]=='n' and user_choices[2] == 'y' and user_choices[3] == '':
final_list += numbers
elif user_choices[1]=='y' and user_choices[2] == 'n' and user_choices[3] == 'y':
final_list += upper_case_letters + special_chars
password= 'p'
for character in random.sample(final_list, length):
password+=character
print(f"Generated password: {password[1:]}")