Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- def menu():
- choice = input("Welcome to the Quiz Menu, \n 1. Login \n 2. Register \n 3. Quit \n")
- if choice == '1':
- login()
- elif choice == '2':
- register()
- else:
- quit()
- def login():
- with open('users.csv') as csvfile:
- reader = csv.DictReader(csvfile)
- database = []
- for row in reader:
- database.append(dict(username=row['username'],
- password=row['password'],
- admin=row['admin']))
- loggedin = False
- while not loggedin:
- Username = input('Fill in your username: ')
- Password = input('Fill in your password: ')
- for row in database:
- Username_File = row['username']
- Password_File = row['password']
- Admin_File = row['admin']
- if (Username_File == Username and
- Password_File == Password and
- Admin_File == '0'):
- loggedin = True
- print('Succesfully logged in as a Student.')
- elif (Username_File == Username and
- Password_File == Password and
- Admin_File == '1'):
- loggedin = True
- print('Succesfully logged in as an Admin.')
- if loggedin is not True:
- print ('Failed to sign in, wrong username or password.')
- def register():
- with open('users.csv') as csvfile:
- reader = csv.DictReader(csvfile)
- database = []
- for row in reader:
- database.append(dict(Name_File = row['first_name'],
- LName_File = row['last_name'],
- Password_File = row['password'],
- Age_File = row['age'],
- YearGroup_File = row['year_group']))
- register = False
- while register is not True:
- Name = input('Fill in your name: ')
- database.append(dict(Name_File = row['first_name']))
- LName = input('Fill in your last name: ')
- database.append(dict(LName_File = row['last_name']))
- Age = input('Fill in your age: ')
- database.append(dict(Age = row['age']))
- YearGroup = input('Fill in your year group ')
- database.append(dict(YearGroup = row['year_group']))
- Password = input('Fill in your password ')
- database.append(dict(Password = row['password']))
- Username = (Name[:3]+Age)
- print("Your username is :", Username)
- database.append(dict(Username = row['username']))
- register = True
- print("You've Succesfully Registered")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement