forked from DhanushNehru/Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordGenerator.py
96 lines (69 loc) · 2.02 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
88
89
90
91
92
93
94
95
96
import random as rr
import string as ss
"""
ASCII
A -> Z : 65 -> 90
a -> z : 97 -> 122
"""
characters = ['@', '#', '$', '%', '&', '?']
pass_len = int(input('How lengthy do you want your password to be : '))
tempy, tempz = 0, 0
tempx = rr.randint(2, pass_len-1) # alphabets
if tempx != pass_len:
tempy = rr.randint(1, (pass_len - tempx - 1)) # numbers
total_nums = tempy
if (tempx + tempy) != pass_len:
tempz = rr.randint(1, (pass_len-(tempx+tempy))) # special characters
total_symbols = tempz
# password : empty string for now
pass_word = ''
# adding alphabets
while tempx:
x = tempx
num_cap = rr.randint(0, x)
num_low = x-num_cap
total_cap = num_cap
total_low = num_low
# capitals in password :
while num_cap:
temp = chr(rr.randint(65, 90))
pass_word = pass_word + str(temp)
num_cap -= 1
# lower-case in password :
while num_low:
temp = chr(rr.randint(97, 122))
pass_word = pass_word + str(temp)
num_low -= 1
break
# adding numbers to the password
while tempy:
temp = (rr.randint(0, 9))
pass_word = pass_word + str(temp)
tempy -= 1
# adding special characters to the password
while tempz:
temp = rr.randint(0, len(characters)-1)
pass_word = pass_word + characters[temp]
tempz -= 1
#shuffles the string
def shuffle_(alpha):
str_temp = list(alpha)
rr.shuffle(str_temp)
alpha = ''.join(str_temp)
return alpha
#adds colour to the text
def colored(r, g, b, text):
return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
final_pass =colored(200,200,50, (shuffle_(shuffle_(shuffle_(pass_word)))))
# result & summary
result = """
Generate Password Summary :
Charactor Uppercase : {0}
Charactor 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)
# print(f"\nYour computer generated password is : {final_pass}\n\n")