Advertisement
Guest User

Untitled

a guest
Nov 9th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. def login():
  2.     creds = 'credfile.tmp'
  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.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.             else:
  19.                 print("Wrong Username or Password")
  20.                 return False
  21.         except:
  22.             print("No users")
  23.             return False
  24.     elif userOption == "no":
  25.         name=input("Enter your first name : ")
  26.         age=int(input("Enter your age : "))
  27.         yearGroup=input("Enter your year group : ")
  28.         newUser = name[:3]+str(age)
  29.         print("Your username will be, " + newUser)
  30.         newPassw=input("Please enter a password for your account. (Minimum 6 characters long) : ")
  31.         if len(newPassw) < 6:
  32.             print("Password length is too short!")
  33.             return False
  34.         with open(creds, 'a')as f:
  35.             f.write(newUser + ";" + newPassw)
  36.         print("You have successfully created your account!")
  37.         return False
  38.  
  39.  
  40. while True:
  41.     login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement