forked from DhanushNehru/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordGenerator.py
87 lines (59 loc) · 2.1 KB
/
PasswordGenerator.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
75
76
77
78
79
80
81
82
83
84
85
86
87
import random as rr
import string as ss
characters = ['@', '#', '$', '%', '&', '?']
def generate_password(pass_len):
# Initialize counters
total_nums = 0
total_symbols = 0
total_cap = 0
total_low = 0
# Ensure at least one of each type
tempx = rr.randint(2, max(2, pass_len - 2)) # at least 2 letters
remaining = pass_len - tempx
tempy = rr.randint(1, max(1, remaining - 1)) # at least 1 number
remaining -= tempy
total_nums = tempy
tempz = remaining # rest goes to special characters
total_symbols = tempz
# Generate password
pass_word = ''
# Add alphabets
num_cap = rr.randint(1, tempx - 1) # at least 1 uppercase
num_low = tempx - num_cap # rest lowercase
total_cap = num_cap
total_low = num_low
# Add capitals
pass_word += ''.join(chr(rr.randint(65, 90)) for _ in range(num_cap))
# Add lowercase
pass_word += ''.join(chr(rr.randint(97, 122)) for _ in range(num_low))
# Add numbers
pass_word += ''.join(str(rr.randint(0, 9)) for _ in range(tempy))
# Add special characters
pass_word += ''.join(rr.choice(characters) for _ in range(tempz))
return pass_word, total_cap, total_low, total_nums, total_symbols
def shuffle_(alpha):
str_temp = list(alpha)
rr.shuffle(str_temp)
return ''.join(str_temp)
def colored(r, g, b, text):
return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
def main():
pass_len = int(input('How lengthy do you want your password to be : '))
if pass_len < 4:
print("Password length must be at least 4 characters")
return
pass_word, total_cap, total_low, total_nums, total_symbols = generate_password(pass_len)
# Shuffle multiple times
final_pass = colored(200, 200, 50, shuffle_(shuffle_(shuffle_(pass_word))))
result = """
Generate Password Summary:
Character Uppercase : {0}
Character Lowercase : {1}
Numbers : {2}
Symbols : {3}
Your computer generated password is:
{4}
""".format(total_cap, total_low, total_nums, total_symbols, final_pass)
print(result)
if __name__ == "__main__":
main()