Advertisement
Guest User

Untitled

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