Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from os import urandom
- from random import choice
- char_set = {'small': 'abcdefghijklmnopqrstuvwxyz',
- 'nums': '0123456789',
- 'big' : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
- 'special': '^!\$%&/()=?{[]}+~#-_.:,;<>|\\'
- }
- # Generate a password
- def generate_pass(lenght=16):
- password = []
- while len(password) < lenght:
- key = choice(char_set.keys())
- a_char = urandom(1)
- if a_char in char_set[key]:
- if check_prev_char(password, char_set[key]):
- continue
- else:
- password.append(a_char)
- return ''.join(password)
- # Function to ensure that there are no consecutive
- # UPPERCASE/lowercase/numbers/special-characters.
- def check_prev_char(password, current_char_set):
- 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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement