Skip to content

Commit 5258884

Browse files
authored
Create passgenv2.py
1 parent 01ef0af commit 5258884

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

passgenv2.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from os import urandom
2+
from random import choice
3+
4+
char_set = {'small': 'abcdefghijklmnopqrstuvwxyz',
5+
'nums': '0123456789',
6+
'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
7+
'special': '^!\$%&/()=?{[]}+~#-_.:,;<>|\\'
8+
}
9+
10+
11+
def generate_pass(length=15):
12+
"""Function to generate a password"""
13+
14+
password = []
15+
16+
while len(password) < length:
17+
key = choice([char_set["small"],char_set["big"],char_set["special"],char_set["nums"]])
18+
a_char = urandom(1)
19+
n = choice(key)
20+
if n in key:
21+
if check_prev_char(password, n):
22+
continue
23+
else:
24+
password.append(n)
25+
return ''.join(password)
26+
27+
28+
def check_prev_char(password, current_char_set):
29+
"""Function to ensure that there are no consecutive
30+
UPPERCASE/lowercase/numbers/special-characters."""
31+
32+
index = len(password)
33+
if index == 0:
34+
return False
35+
else:
36+
prev_char = password[index - 1]
37+
if prev_char in current_char_set:
38+
return True
39+
else:
40+
return False
41+
42+
if __name__ == '__main__':
43+
print(generate_pass())

0 commit comments

Comments
 (0)