-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpassgenv2.py
More file actions
43 lines (34 loc) · 1.12 KB
/
passgenv2.py
File metadata and controls
43 lines (34 loc) · 1.12 KB
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
from os import urandom
from random import choice
char_set = {'small': 'abcdefghijklmnopqrstuvwxyz',
'nums': '0123456789',
'big': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'special': '^!\$%&/()=?{[]}+~#-_.:,;<>|\\'
}
def generate_pass(length=15):
"""Function to generate a password"""
password = []
while len(password) < length:
key = choice([char_set["small"],char_set["big"],char_set["special"],char_set["nums"]])
a_char = urandom(1)
n = choice(key)
if n in key:
if check_prev_char(password, n):
continue
else:
password.append(n)
return ''.join(password)
def check_prev_char(password, current_char_set):
"""Function to ensure that there are no consecutive
UPPERCASE/lowercase/numbers/special-characters."""
index = len(password)
if index == 0:
return False
else:
prev_char = password[index - 1]
if prev_char in current_char_set:
return True
else:
return False
if __name__ == '__main__':
print(generate_pass())