Advertisement
Guest User

Untitled

a guest
Nov 9th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. def login():
  2.     creds = 'credfile.txt'
  3.     userOption = input("Do you own an account? Please type yes or no.")
  4.     if userOption == "yes":
  5.         try:
  6.             usersfile = open(creds, 'r')
  7.             users = {}
  8.             for l in usersfile:
  9.                 lsplit = l.strip().split(";")
  10.                 users[lsplit[0]] = lsplit[1]
  11.             print("Please login.\n")
  12.             user = input('Enter username: ')
  13.             passwd = input('Enter password: ')
  14.             if (user, passwd) in users.items():
  15.                 print('\n[+] Logged In\n')
  16.                 # SUCCESS DO SOMETHING
  17.                 return True
  18.             elif user == "Fergus" and passwd == "AVeryAmazingPassword":
  19.                 print('\n[+] Logged In as Fergus\n')
  20.                 # SUCCESS DO FERGUS THINGS
  21.             else:
  22.                 print("Wrong Username or Password")
  23.                 return False
  24.         except:
  25.             print("No users")
  26.             return False
  27.     elif userOption == "no":
  28.         name=input("Enter your first name : ")
  29.         age=int(input("Enter your age : "))
  30.         yearGroup=input("Enter your year group : ")
  31.         newUser = name[:3]+str(age)
  32.         print("Your username will be, " + newUser)
  33.         newPassw=input("Please enter a password for your account. (Minimum 6 characters long) : ")
  34.         if len(newPassw) < 6:
  35.             print("Password length is too short!")
  36.             return False
  37.         with open(creds, 'a')as f:
  38.             f.write(newUser + ";" + newPassw + '\n')
  39.         print("You have successfully created your account!")
  40.         return False
  41.  
  42.  
  43. while True:
  44.     login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement