Skip to content

Commit d54329e

Browse files
authored
Merge pull request #5 from mclmza/master
Password generator
2 parents e4dcb68 + 1af8505 commit d54329e

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

PasswordGenerator.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import random as rr
2+
import string as ss
3+
4+
5+
6+
"""
7+
ASCII
8+
A -> Z : 65 -> 90
9+
a -> z : 97 -> 122
10+
"""
11+
12+
characters = ['@', '#', '$', '%', '&', '?']
13+
14+
15+
pass_len = int(input('How lengthy do you want your password to be : '))
16+
17+
tempy, tempz = 0, 0
18+
19+
tempx = rr.randint(2, pass_len-1) # alphabets
20+
21+
print(f'\nAlphabets : {tempx}')
22+
23+
if tempx != pass_len:
24+
tempy = rr.randint(1, (pass_len - tempx - 1)) # numbers
25+
26+
print(f'Numbers : {tempy}')
27+
28+
if (tempx + tempy) != pass_len:
29+
tempz = rr.randint(1, (pass_len-(tempx+tempy))) # special characters
30+
31+
print(f'Characters : {tempz}')
32+
33+
# password : empty string for now
34+
pass_word = ''
35+
36+
# adding alphabets
37+
38+
while tempx:
39+
x = tempx
40+
num_cap = rr.randint(0, x)
41+
num_low = x-num_cap
42+
43+
# capitals in password :
44+
while num_cap:
45+
temp = chr(rr.randint(65, 90))
46+
pass_word = pass_word + str(temp)
47+
num_cap -= 1
48+
49+
# lower-case in password :
50+
while num_low:
51+
temp = chr(rr.randint(97, 122))
52+
pass_word = pass_word + str(temp)
53+
num_low -= 1
54+
55+
break
56+
57+
# adding numbers to the password
58+
while tempy:
59+
temp = (rr.randint(0, 9))
60+
pass_word = pass_word + str(temp)
61+
tempy -= 1
62+
63+
# adding special characters to the password
64+
while tempz:
65+
temp = rr.randint(0, len(characters)-1)
66+
pass_word = pass_word + characters[temp]
67+
tempz -= 1
68+
69+
#shuffles the string
70+
def shuffle_(alpha):
71+
str_temp = list(alpha)
72+
rr.shuffle(str_temp)
73+
alpha = ''.join(str_temp)
74+
return alpha
75+
76+
#adds colour to the text
77+
def colored(r, g, b, text):
78+
return "\033[38;2;{};{};{}m{} \033[38;2;255;255;255m".format(r, g, b, text)
79+
80+
final_pass =colored(200,200,50, (shuffle_(shuffle_(shuffle_(pass_word)))))
81+
82+
print(f"\nYour computer generated password is : {final_pass}\n\n")

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ FakeProfile.py
4343
## Script 8 - Digital Clock
4444

4545
DigitalClock.py
46+
47+
48+
## Script 8 - Digital Clock
49+
50+
Generate a random password

0 commit comments

Comments
 (0)