Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import random
  2.  
  3. alphabet = 'qazwsxedcrfvtgbyhnujmiklp'
  4. numbers = '1234567890'
  5. alphabet_upper = 'QAZWSXEDCRFVTGBYHNUJMIKOLP'
  6. symbols = '_-$&№@'
  7.  
  8. def generate_password(length, count_num, count_sym=0, count_uppers=0):
  9.  
  10. count_alpha = length - count_num - count_sym - count_uppers
  11.  
  12. counts = [count_alpha, count_uppers, count_num, count_sym]
  13. lists = [alphabet, alphabet_upper, numbers, symbols]
  14.  
  15. password = []
  16. for lst, count in zip(lists, counts):
  17. password = password + [random.choice(lst) for i in range(count)]
  18.  
  19. random.shuffle(password)
  20. password = ''.join(password)
  21. return password
  22.  
  23. def _test():
  24.  
  25. def get_user_int(msg):
  26. '''
  27. Return integer from user.
  28. :param msg:
  29. :return user_input:
  30. '''
  31. user_input = input(msg)
  32. try:
  33. user_input = int(user_input)
  34. except:
  35. print("Something wrong...")
  36. return user_input
  37.  
  38. length = get_user_int('Input a length for a password -> ')
  39. count_num = get_user_int('How much numbers?-> ')
  40. count_sym = get_user_int('How much symbols?-> ')
  41. count_uppers = get_user_int('How much uppercases?-> ')
  42.  
  43. password = generate_password(length, count_num, count_sym, count_uppers)
  44.  
  45. print('Password successfully generated.\n' + password)
  46.  
  47. if __name__ == '__main__':
  48. _test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement