Advertisement
timber101

07_Password_part2

Jan 30th, 2022
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None
  1. """
  2. Have the program create random strong passwords mixing upper and lower case,
  3. symbols and numbers.
  4. The user can choose how long they want the password to be.
  5. A strong password must contain:
  6. • a capital letter
  7. • a number
  8. • a symbol.
  9.  
  10. """
  11. import random
  12.  
  13. caps =[] # A = 65 Z = 90
  14. numb = [] #48-57
  15. symb = [] # 33-47, 58-64, 123-126
  16. lows = [] #97 122
  17. alls = []
  18.  
  19. for i in range(65,91):
  20. caps.append(chr(i))
  21.  
  22. for i in range(97,123):
  23. lows.append(chr(i))
  24.  
  25. for i in range(48,58):
  26. numb.append(chr(i))
  27.  
  28. for i in range(33,48):
  29. symb.append(chr(i))
  30.  
  31. for i in range(58,65):
  32. symb.append(chr(i))
  33.  
  34. for i in range(123,127):
  35. symb.append(chr(i))
  36.  
  37. # populates the alls list
  38. alls.extend(caps)
  39. alls.extend(numb)
  40. alls.extend(symb)
  41. alls.extend(lows)
  42.  
  43. #print(alls)
  44.  
  45. chars_needed = int()
  46. password=[] # to hold the password
  47.  
  48. while chars_needed <3:
  49. chars_needed = int(input("Enter number of characters you'd like (min 3) >> "))
  50.  
  51. password.append(random.choice(caps))
  52. password.append(random.choice(numb))
  53. password.append(random.choice(symb))
  54. #print(password)
  55.  
  56. for i in range(chars_needed-3):
  57. password.append(random.choice(alls))
  58. random.shuffle(password)
  59.  
  60. passwordstring = ""
  61. for i in range(len(password)):
  62. passwordstring += password[i]
  63. #passwordstring = passwordstring + password[i]
  64. print(password)
  65. print(passwordstring)
  66.  
  67.  
Advertisement
RAW Paste Data Copied
Advertisement