Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.78 KB | None | 0 0
  1. ## Password Program v2 ##
  2. ## ~~ FEATURES ~~ ##
  3. ## Allows Users to Login!
  4. ## Allows users to create unlimited accounts.
  5. ## Uses Text documents to store user data.
  6. ## Forms of verification to protect users data from being over written.
  7. ## Password checking.
  8. ## Forces user to create a complex password.
  9.  
  10. import getpass
  11. import time
  12. import linecache
  13.  
  14. def attemptLogin(username, password):
  15.     try:
  16.         correctPassword = str(linecache.getline(username + ".txt", 1)).rstrip()
  17.  
  18.     except IOError:
  19.         return "Failed to find account!"
  20.  
  21.     # Assume the account exists so far
  22.     if password == correctPassword:
  23.         return True
  24.     else:
  25.         return False
  26.  
  27. def createAccount(username, password, confirmPass):
  28.     if password != confirmPass:
  29.         return False
  30.     else:
  31.         try:
  32.             file = open(username + '.txt', 'r')
  33.             return False
  34.  
  35.         except IOError:
  36.             file = open(username + '.txt', 'w')
  37.             file.write(Password)
  38.             file.close()
  39.             return True
  40.  
  41. def changePass(username, oldPassword, newPassword, newPasswordConfirm):
  42.     if oldPassword == newPassword or newPassword != newPasswordConfirm:
  43.         return False
  44.  
  45.     try:
  46.         correctPassword = str(linecache.getline(username + ".txt", 1)).rstrip()
  47.     except IOError:
  48.         return False
  49.  
  50.     # Shows account exits
  51.     # Validates new password
  52.  
  53.     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():
  54.         # Just checked has number(s), has lower case, has upper case and has a length greater than 8, and their old password is correct.
  55.         file = open(username + '.txt', 'w')
  56.         file.write(newPassword)
  57.         file.close()
  58.         return True
  59.  
  60.     else:
  61.         return False
  62.  
  63. while True:
  64.     selectOption = input("Select option: Attempt Login (L), Create Account (C), Change Password (P): ")
  65.  
  66.     if selectOption == 'L':
  67.         userName = input("Username: ")
  68.         password = getpass.getpass('Password: ')
  69.         if attemptLogin(userName, password) == True:
  70.             print("Login Successful!")
  71.         else:
  72.             print("Login Failed")
  73.  
  74.     elif selectOption == 'C':
  75.         userName = input("Username: ")
  76.         password = getpass.getpass('Password: ')
  77.         confirmPassword = getpass.getpass('Confirm Password: ')
  78.         if createAccount(userName, password, confirmPassword):
  79.             print('Account Creation Successful!')
  80.         else:
  81.             print('Failed to create account!')
  82.  
  83.     elif selectOption == 'P':
  84.         userName = input("Username: ")
  85.         password = getpass.getpass('Old Password: ')
  86.         newPassword = getpass.getpass('New Password: ')
  87.         confirmPassword = getpass.getpass('Confirm New Password: ')
  88.  
  89.         if changePass(userName, password, newPassword, confirmPassword) == True:
  90.             print('Password Successfully Changed!')
  91.         else:
  92.             print("Failed to change password!")
  93.    
  94.     else:
  95.         print("Invalid Option!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement