Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. from random import *
  2. import csv
  3. import string
  4. def menu_selector():
  5. #gets user input and validates it.
  6. invalid_input = True
  7. while invalid_input:
  8. try:
  9. user_choice = int(input('choose an option'))
  10. if user_choice == 1:
  11. #print('Register was selected')
  12. register_user()
  13. invalid_input = False
  14. elif user_choice == 2:
  15. #print('Login was selected')
  16. login_user()
  17. invalid_input = False
  18. elif user_choice == 3:
  19. #print('Quit was selected')
  20. invalid_input = False
  21. exit()
  22. else:
  23. print('Only numbers 1, 2 or 3 can be entered')
  24. except ValueError:
  25. print('Only numbers 1, 2 or 3 can be entered')
  26.  
  27.  
  28. def register_user():
  29. print('Register user invoked')
  30. write_user_data()
  31.  
  32.  
  33. def login_user():
  34. print('Login user invoked')
  35.  
  36.  
  37. def main_menu():
  38. #displays main menu
  39. title = '''
  40. Welcome to my system
  41. --------------------'''
  42. menu = '''
  43. 1. Register
  44. 2. Login
  45. 3. Quit'''
  46.  
  47. print(title)
  48. print()
  49. print(menu)
  50. menu_selector()
  51.  
  52. def loginmenu():
  53. title = '''
  54. Welcome ''', username , '''
  55. ---------------------------'''
  56. menu = '''
  57. 1. Quiz
  58. 2. Manage (Admin Only)
  59. 3. Quit'''
  60.  
  61. print(title)
  62. print()
  63. print(menu)
  64.  
  65.  
  66. def test():
  67. print("Complete")
  68.  
  69.  
  70.  
  71. def login():
  72. with open("student_data.csv", "r") as file:
  73. read=csv.reader(file)
  74. invalid_login = True
  75. while invalid_login:
  76. username = input ('What is your username')
  77. password = input ('What is your password')
  78. for each in read:
  79. print (each)
  80. if username in each and password in each:
  81. print ('record was found')
  82. invalid_login = False
  83.  
  84. else:
  85. print('Incorrect username or password')
  86.  
  87.  
  88.  
  89. def get_validate_userdata():
  90. missing_data = True
  91. while missing_data:
  92. name = input ('Enter your name: ')
  93. surname = input ('Enter your surname: ')
  94. age = input ('Enter your age')
  95. group = input ('Enter your yeargroup: ')
  96. password = password_check()
  97. if name == '' or surname == '' or group == '' or password == '' or age == '':
  98. print ('Fields cannot be blank')
  99. else:
  100. missing_data = False
  101. username =str(randint(10,99))+name[0:2]+surname[0:2]
  102. return (username, name, surname, group, age, password)
  103. break
  104.  
  105. def password_check():
  106. incorrect_data = True
  107. while incorrect_data:
  108. password = input ('Enter your password: ')
  109. for each in password:
  110. if each in string.ascii_uppercase:
  111. print('')
  112. incorrect_data = False
  113. break
  114. else:
  115. print ('Weak password, Your password must contain a capital letter')
  116. return password
  117.  
  118. def write_user_data():
  119. data = get_validate_userdata()
  120. data_to_write = []
  121. for each in data:
  122. data_to_write.append(each)
  123. print (data_to_write)
  124. with open ('student_data.csv','a',newline="") as studentFile:
  125. studentFileWriter = csv.writer(studentFile)
  126. studentFileWriter.writerow(data_to_write)
  127. print('data written successfully')
  128. studentFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement