Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Name: password_pin_generator.py
  3. # Purpose: Generates a random password or PIN of varying strength levels and saves the password or PIN to a file.
  4. #
  5. # Author: Lam.M
  6. #
  7. # Created: 02/10/2015
  8. # Copyright: (c) LamM0150 2015
  9. # Licence: <your licence>
  10. #-------------------------------------------------------------------------------
  11. import random
  12.  
  13. #Ask if the user wants a PIN or password
  14. user_type = raw_input("Do you want to generate a PIN or a password? (PIN/password): ").lower()
  15. if user_type == "password":
  16.  
  17.  
  18. #Possible characters for the password and open saved_password.txt
  19. possible_password = "1234567890-=qwertyuip[]\asdfghjkl;'zxcvbnm,./`*~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:/ASDFGHJKLZXCVBNM<>?*"
  20. saved_password = open("saved_password.txt", "a")
  21. #Varying password length for different strength levels
  22. pass_len_weak = 3
  23. pass_len_medium = 8
  24. pass_len_strong = 12
  25.  
  26. #Generate passwords
  27. password_weak = "".join(random.sample(possible_password, pass_len_weak))
  28. password_medium = "".join(random.sample(possible_password, pass_len_medium))
  29. password_strong = "".join(random.sample(possible_password, pass_len_strong))
  30.  
  31. #Ask the user what the password is for
  32. password_use = raw_input("What are you using this password for?: ")
  33. saved_password.write(password_use + "\n")
  34.  
  35. #Ask user for strength level
  36. user = raw_input("How strong do you want your password? (weak/medium/strong): ").lower()
  37.  
  38. #Output password and ask user to confirm then saves it to saved_password.txt
  39. if user == "weak":
  40. print password_weak
  41. confirm_password = raw_input("Please confirm your password: ")
  42. if confirm_password == password_weak:
  43. saved_password.write(password_weak + "\n")
  44. saved_password.close()
  45. else:
  46. print "Please try again."
  47. elif user == "medium":
  48. print password_medium
  49. confirm_password = raw_input("Please confirm your password: ")
  50. if confirm_password == password_medium:
  51. saved_password.write(password_medium + "\n")
  52. saved_password.close()
  53. else:
  54. print "Please try again."
  55. elif user == "strong":
  56. print password_strong
  57. confirm_password = raw_input("Please confirm your password: ")
  58. if confirm_password == password_strong:
  59. saved_password.write(password_strong + "\n")
  60. saved_password.close()
  61. else:
  62. print "Please try again"
  63. else:
  64. print "Please pick a valid strength level. (weak/medium/strong)"
  65.  
  66. elif user_type == "pin":
  67.  
  68. #Possible numbers for the PIN and open saved_pin.txt
  69. possible_pin = "1234567890"
  70. saved_pin = open("saved_pin.txt", "a")
  71. pin_use = raw_input("What are you using this PIN for?: ")
  72. saved_pin.write(pin_use + "\n")
  73.  
  74. #Generate PIN
  75. pin = "".join(random.sample(possible_pin, 4))
  76.  
  77. #Output PIN and ask user to confirm before saving it to saved_pin.txt
  78. print pin
  79. confirm_pin = raw_input("Please confirm your PIN: ")
  80. if confirm_pin == pin:
  81. saved_pin.write(pin + "\n")
  82. saved_pin.close()
  83. else:
  84. print "Please try again."
  85.  
  86. else:
  87. "Pick either a PIN or a password. (PIN/password)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement