Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # Name: password_pin_generator.py
- # Purpose: Generates a random password or PIN of varying strength levels and saves the password or PIN to a file.
- #
- # Author: Lam.M
- #
- # Created: 02/10/2015
- # Copyright: (c) LamM0150 2015
- # Licence: <your licence>
- #-------------------------------------------------------------------------------
- import random
- #Ask if the user wants a PIN or password
- user_type = raw_input("Do you want to generate a PIN or a password? (PIN/password): ").lower()
- if user_type == "password":
- #Possible characters for the password and open saved_password.txt
- possible_password = "1234567890-=qwertyuip[]\asdfghjkl;'zxcvbnm,./`*~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:/ASDFGHJKLZXCVBNM<>?*"
- saved_password = open("saved_password.txt", "a")
- #Varying password length for different strength levels
- pass_len_weak = 3
- pass_len_medium = 8
- pass_len_strong = 12
- #Generate passwords
- password_weak = "".join(random.sample(possible_password, pass_len_weak))
- password_medium = "".join(random.sample(possible_password, pass_len_medium))
- password_strong = "".join(random.sample(possible_password, pass_len_strong))
- #Ask the user what the password is for
- password_use = raw_input("What are you using this password for?: ")
- saved_password.write(password_use + "\n")
- #Ask user for strength level
- user = raw_input("How strong do you want your password? (weak/medium/strong): ").lower()
- #Output password and ask user to confirm then saves it to saved_password.txt
- if user == "weak":
- print password_weak
- confirm_password = raw_input("Please confirm your password: ")
- if confirm_password == password_weak:
- saved_password.write(password_weak + "\n")
- saved_password.close()
- else:
- print "Please try again."
- elif user == "medium":
- print password_medium
- confirm_password = raw_input("Please confirm your password: ")
- if confirm_password == password_medium:
- saved_password.write(password_medium + "\n")
- saved_password.close()
- else:
- print "Please try again."
- elif user == "strong":
- print password_strong
- confirm_password = raw_input("Please confirm your password: ")
- if confirm_password == password_strong:
- saved_password.write(password_strong + "\n")
- saved_password.close()
- else:
- print "Please try again"
- else:
- print "Please pick a valid strength level. (weak/medium/strong)"
- elif user_type == "pin":
- #Possible numbers for the PIN and open saved_pin.txt
- possible_pin = "1234567890"
- saved_pin = open("saved_pin.txt", "a")
- pin_use = raw_input("What are you using this PIN for?: ")
- saved_pin.write(pin_use + "\n")
- #Generate PIN
- pin = "".join(random.sample(possible_pin, 4))
- #Output PIN and ask user to confirm before saving it to saved_pin.txt
- print pin
- confirm_pin = raw_input("Please confirm your PIN: ")
- if confirm_pin == pin:
- saved_pin.write(pin + "\n")
- saved_pin.close()
- else:
- print "Please try again."
- else:
- "Pick either a PIN or a password. (PIN/password)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement