Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. def mainmenu():
  2. print ("""
  3. ################################################################################
  4. # #
  5. # clive's carpets #
  6. # login below! #
  7. # #
  8. ################################################################################
  9. """)
  10. validateuser()
  11. def adminmenu():
  12.  
  13. print ("""
  14. ################################################################################
  15. # #
  16. # clive's carpets #
  17. # admin menu #
  18. # #
  19. # #
  20. # 1 - add a new user #
  21. # 2 - exit #
  22. # #
  23. ################################################################################
  24. """)
  25. adminmenu = input("\nWhat option would you like to chose? 1 or 2?: \n")
  26. while True:
  27. if adminmenu == "1":
  28. newuser()
  29. break
  30. elif adminmenu == "2":
  31. mainmenu()
  32. break
  33. def usermenu():
  34. print("""
  35. ################################################################################
  36. # #
  37. # clive's carpets #
  38. # user menu #
  39. # #
  40. ################################################################################
  41. """)
  42. def newuser():
  43. usertype, username, password1, password2 = "", "", "", ""
  44.  
  45. while True:
  46.  
  47. usertype = input("what type of user are you creating\n(1)Admin \n(2)User\nType -1 to exit to the mainn menu\n")
  48. if usertype == "-1":
  49. mainmenu()
  50. if len(usertype) > 1:
  51. print("\ninvalid input!\n")
  52. elif usertype.isdigit() != True:
  53. print("\nplease enter a number: \n")
  54. elif int (usertype) <1:
  55. print("\ninvalid input!\n")
  56. elif int (usertype) >2:
  57. print("\ninvalid input!\n")
  58. else:
  59. break
  60.  
  61. while True:
  62.  
  63. username = input("\nEnter the name of new user: \n")
  64. if username == "-1":
  65. mainmenu()
  66. if len (username) > 10:
  67. print ("\nusermane must be less than 11 chars: \n")
  68. elif username.isalpha() == False:
  69. print ("\nthe usermane must contain alpha!\n")
  70. else:
  71. break
  72. while True:
  73. password1 = input("what is your password?\n")
  74. if password1 == "-1":
  75. mainmenu()
  76. if len (password1) >10:
  77. print ("\npassword must be less than 11 chars: \n")
  78.  
  79. password2 = input("AGAIN!\n")
  80. if password2 == "-1":
  81. mainmenu()
  82. if len (password2) >10:
  83. print ("\npassword must be less than 11 chars: \n")
  84. if password1 != password2:
  85. print ("\npassword does not match: \n")
  86. else:
  87. break
  88.  
  89. username = username.lower()
  90. password1 = password1.lower()
  91. password2 = password2.lower()
  92.  
  93.  
  94. usertypestore = str(usertype).ljust(1)
  95. usernamestore = username.ljust(10)
  96. passwordstore = password1.ljust(10)
  97.  
  98. store = open ("users.txt","a")
  99. istore = usernamestore + passwordstore + usertypestore + "\n"
  100. store.write(istore)
  101. store.close()
  102.  
  103. print("\nNew user added: ")
  104. print("usertype: ",usertype)
  105. print("username: ",username)
  106. print("Password: *********")
  107. def validateuser():
  108. validateusertype, validateusername, validatepassword = "","",""
  109.  
  110.  
  111. username = str(input("\nplease enter your username: \n"))
  112. password = str(input("\nplease enter your password: \n"))
  113.  
  114. while True:
  115. try:
  116. readusers = open("users.txt","r")
  117. validatecounter = 0
  118.  
  119. while True:
  120. location = readusers.readline()
  121. validateusertype = location[20:21]
  122. validateusertype = validateusertype.strip()
  123.  
  124. validateusername = location[0:10]
  125. validateusername = validateusername.strip()
  126. validateusername = validateusername.lower()
  127. username = username.lower()
  128.  
  129. validatepassword = location[10:20]
  130. validatepassword = validatepassword.strip()
  131. validatepassword = validatepassword.lower()
  132.  
  133.  
  134. if location == "":
  135. readusers.close()
  136. break
  137. if validateusertype == str(1) and validateusername == username and validatepassword == password:
  138. validatecounter = validatecounter + 1
  139. adminmenu()
  140. break
  141. if validateusertype == str(2) and validateusername == username and validatepassword == password:
  142. validatecounter = validatecounter + 1
  143. usermenu()
  144. break
  145. if validatecounter == 0:
  146. print ("\nNo user in file with login details\n")
  147. validateuser()
  148.  
  149. except FileNotFoundError:
  150. print("\nthere is no user file to search. How about making a new account? \n")
  151. newuser()
  152. def main():
  153. mainmenu()
  154. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement