Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Password Program v2 ##
- ## ~~ FEATURES ~~ ##
- ## Allows Users to Login!
- ## Allows users to create unlimited accounts.
- ## Uses Text documents to store user data.
- ## Forms of verification to protect users data from being over written.
- ## Password checking.
- ## Forces user to create a complex password.
- import getpass
- import time
- import linecache
- def attemptLogin(username, password):
- try:
- correctPassword = str(linecache.getline(username + ".txt", 1)).rstrip()
- except IOError:
- return "Failed to find account!"
- # Assume the account exists so far
- if password == correctPassword:
- return True
- else:
- return False
- def createAccount(username, password, confirmPass):
- if password != confirmPass:
- return False
- else:
- try:
- file = open(username + '.txt', 'r')
- return False
- except IOError:
- file = open(username + '.txt', 'w')
- file.write(Password)
- file.close()
- return True
- def changePass(username, oldPassword, newPassword, newPasswordConfirm):
- if oldPassword == newPassword or newPassword != newPasswordConfirm:
- return False
- try:
- correctPassword = str(linecache.getline(username + ".txt", 1)).rstrip()
- except IOError:
- return False
- # Shows account exits
- # Validates new password
- if any(x.isdigit() for x in newPassword) == True and newPassword.upper() != newPassword and newPassword.lower() != newPassword and len(newPassword) >= 8 and oldPassword == str(linecache.getline(username + ".txt", 1)).rstrip():
- # Just checked has number(s), has lower case, has upper case and has a length greater than 8, and their old password is correct.
- file = open(username + '.txt', 'w')
- file.write(newPassword)
- file.close()
- return True
- else:
- return False
- while True:
- selectOption = input("Select option: Attempt Login (L), Create Account (C), Change Password (P): ")
- if selectOption == 'L':
- userName = input("Username: ")
- password = getpass.getpass('Password: ')
- if attemptLogin(userName, password) == True:
- print("Login Successful!")
- else:
- print("Login Failed")
- elif selectOption == 'C':
- userName = input("Username: ")
- password = getpass.getpass('Password: ')
- confirmPassword = getpass.getpass('Confirm Password: ')
- if createAccount(userName, password, confirmPassword):
- print('Account Creation Successful!')
- else:
- print('Failed to create account!')
- elif selectOption == 'P':
- userName = input("Username: ")
- password = getpass.getpass('Old Password: ')
- newPassword = getpass.getpass('New Password: ')
- confirmPassword = getpass.getpass('Confirm New Password: ')
- if changePass(userName, password, newPassword, confirmPassword) == True:
- print('Password Successfully Changed!')
- else:
- print("Failed to change password!")
- else:
- print("Invalid Option!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement