Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- alphabet = 'qazwsxedcrfvtgbyhnujmiklp'
- numbers = '1234567890'
- alphabet_upper = 'QAZWSXEDCRFVTGBYHNUJMIKOLP'
- symbols = '_-$&№@'
- def generate_password(length, count_num, count_sym=0, count_uppers=0):
- count_alpha = length - count_num - count_sym - count_uppers
- counts = [count_alpha, count_uppers, count_num, count_sym]
- lists = [alphabet, alphabet_upper, numbers, symbols]
- password = []
- for lst, count in zip(lists, counts):
- password = password + [random.choice(lst) for i in range(count)]
- random.shuffle(password)
- password = ''.join(password)
- return password
- def _test():
- def get_user_int(msg):
- '''
- Return integer from user.
- :param msg:
- :return user_input:
- '''
- user_input = input(msg)
- try:
- user_input = int(user_input)
- except:
- print("Something wrong...")
- return user_input
- length = get_user_int('Input a length for a password -> ')
- count_num = get_user_int('How much numbers?-> ')
- count_sym = get_user_int('How much symbols?-> ')
- count_uppers = get_user_int('How much uppercases?-> ')
- password = generate_password(length, count_num, count_sym, count_uppers)
- print('Password successfully generated.\n' + password)
- if __name__ == '__main__':
- _test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement