File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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 ())
You can’t perform that action at this time.
0 commit comments