Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import *
- import csv
- import string
- def menu_selector():
- #gets user input and validates it.
- invalid_input = True
- while invalid_input:
- try:
- user_choice = int(input('choose an option'))
- if user_choice == 1:
- #print('Register was selected')
- register_user()
- invalid_input = False
- elif user_choice == 2:
- #print('Login was selected')
- login_user()
- invalid_input = False
- elif user_choice == 3:
- #print('Quit was selected')
- invalid_input = False
- exit()
- else:
- print('Only numbers 1, 2 or 3 can be entered')
- except ValueError:
- print('Only numbers 1, 2 or 3 can be entered')
- def register_user():
- print('Register user invoked')
- write_user_data()
- def login_user():
- login()
- def main_menu():
- #displays main menu
- title = '''
- Welcome to my system
- --------------------'''
- menu = '''
- 1. Register
- 2. Login
- 3. Quit'''
- print(title)
- print()
- print(menu)
- menu_selector()
- def loginmenu(username):
- title = 'Welcome '+ username
- deco = '-'
- menu = '''
- 1. Quiz
- 2. Manage (Admin Only)
- 3. Quit'''
- print(title)
- print(deco *len(title))
- print()
- print(menu)
- def test():
- print("Complete")
- def login():
- with open("student_data.csv", "r") as file:
- read=csv.reader(file)
- invalid_login = True
- while invalid_login:
- username = input ('What is your username')
- password = input ('What is your password')
- for each in read:
- #print (each)
- if username in each and password in each:
- print ('Login Successful')
- invalid_login = False
- break
- elif username not in each and password not in each:
- print('Incorrect username or password')
- loginmenu(username)
- def get_validate_userdata():
- missing_data = True
- while missing_data:
- name = input ('Enter your name: ')
- surname = input ('Enter your surname: ')
- age = input ('Enter your age')
- group = input ('Enter your yeargroup: ')
- password = password_check()
- if name == '' or surname == '' or group == '' or password == '' or age == '':
- print ('Fields cannot be blank')
- else:
- missing_data = False
- username =str(randint(10,99))+name[0:2]+surname[0:2]
- return (username, name, surname, group, age, password)
- break
- def password_check():
- incorrect_data = True
- while incorrect_data:
- password = input ('Enter your password: ')
- for each in password:
- if each in string.ascii_uppercase:
- print('')
- incorrect_data = False
- break
- else:
- print ('Weak password, Your password must contain a capital letter')
- return password
- def write_user_data():
- data = get_validate_userdata()
- data_to_write = []
- for each in data:
- data_to_write.append(each)
- print (data_to_write)
- with open ('student_data.csv','a',newline="") as studentFile:
- studentFileWriter = csv.writer(studentFile)
- studentFileWriter.writerow(data_to_write)
- print('data written successfully')
- studentFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement