forked from ManthanShettigar/FunWithPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwd_gen.py
74 lines (62 loc) · 1.9 KB
/
pwd_gen.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
import sys
import secrets
import string
import random
lowercase_char = string.ascii_lowercase
uppercase_char = string.ascii_uppercase
nums = string.digits
special_char = "!@#$%^&*()=+-~/[]{};:<>`"
password = ''
count = 0
length_error = False
uppercase_error = False
num_error = False
special_error = False
# User input
length = int(input("Required Password Length? "))
uppercase_req = int(input("How many Uppercase letter are Required? "))
num_req = int(input("How many Numbers are required? "))
special_req = int(input("How many special characters are required? "))
def error(length, uppercase_req, num_req, special_req):
global length_error
global uppercase_error
global num_error
global special_error
if (length <= 0):
length_error = True
if (uppercase_req < 0):
uppercase_error = True
if (num_req < 0):
num_error = True
if (special_req < 0):
special_error = True
def make_password(required_count, character_set):
global count
global password
while (count < required_count):
password += secrets.choice(character_set)
count += 1
count = 0
def shuffle(s):
l = list(s)
random.shuffle(l)
return "".join(l)
#Error Message
error(length, uppercase_req, num_req, special_req)
if (length_error):
print("Invalid length!")
if (uppercase_error):
print("Invalid uppercase letter requirement!")
if (num_error):
print("Invalid number requirement!")
if (special_error):
print("Invalid special character requirement!")
if ((not length_error) and (not uppercase_error) and (not num_error) and (not special_error)):
make_password(uppercase_req, uppercase_char)
make_password(num_req, nums)
make_password(special_req, special_char)
make_password(length - len(password), lowercase_char)
print("\nPASSWORD: %s\n" % shuffle(password))
else:
print("Please fix any errors.")
input("Press ENTER to Exit!")