Advertisement
Guest User

Untitled

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