Advertisement
Guest User

finOpenControlledBob

a guest
Nov 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 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. get_validate_userdata()
  31. write_user_data()
  32.  
  33.  
  34. def login_user():
  35. print('Login user invoked')
  36.  
  37.  
  38. def main_menu():
  39. #displays main menu
  40. title = '''
  41. Welcome to my system
  42. --------------------'''
  43. menu = '''
  44. 1. Register
  45. 2. Login
  46. 3. Quit'''
  47.  
  48. print(title)
  49. print()
  50. print(menu)
  51. menu_selector()
  52.  
  53. def loginmenu():
  54. title = '''
  55. Welcome ''', username , '''
  56. ---------------------------'''
  57. menu = '''
  58. 1. Quiz
  59. 2. Manage (Admin Only)
  60. 3. Quit'''
  61.  
  62. print(title)
  63. print()
  64. print(menu)
  65.  
  66.  
  67.  
  68. def login():
  69. with open("student_data.csv", "r") as file:
  70. read=csv.reader(file)
  71. invalid_login = True
  72. while invalid_login:
  73. username = input ('What is your username')
  74. password = input ('What is your password')
  75. for each in read[i]:
  76. print (each)
  77.  
  78. if username in read[i] and password in read[i]:
  79. print ('username and password was found')
  80. loginmenu()
  81. invalid_login = False
  82.  
  83. elif i == len(read)-1:
  84. print('Incorrect username or password')
  85.  
  86.  
  87. def get_validate_userdata():
  88. missing_data = True
  89. while missing_data:
  90. name = input ('Enter your name: ')
  91. surname = input ('Enter your surname: ')
  92. age = input ('Enter your age')
  93. group = input ('Enter your yeargroup: ')
  94. password = password_check()
  95. if name == '' or surname == '' or group == '' or password == '' or age == '':
  96. print ('Fields cannot be blank')
  97. else:
  98. missing_data = False
  99. username =str(randint(10,99))+name[0:2]+surname[0:2]
  100. return (username, name, surname, group, age, password)
  101. break
  102.  
  103. def password_check():
  104. incorrect_data = True
  105. while incorrect_data:
  106. password = input ('Enter your password: ')
  107. for each in password:
  108. if each in string.ascii_uppercase:
  109. print('')
  110. incorrect_data = False
  111. break
  112. else:
  113. print ('Weak password, Your password must contain a capital letter')
  114. return password
  115.  
  116. def write_user_data():
  117. data = get_validate_userdata()
  118. data_to_write = []
  119. for each in data:
  120. data_to_write.append(each)
  121. print (data_to_write)
  122. with open ('student_records.csv','a') as studentFile:
  123. studentFileWriter = csv.writer(studentFile)
  124. studentFileWriter.writerow(data_to_write)
  125. print('data written successfully')
  126. studentFile.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement