Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def mainmenu():
- print ("""
- ################################################################################
- # #
- # clive's carpets #
- # login below! #
- # #
- ################################################################################
- """)
- validateuser()
- def adminmenu():
- print ("""
- ################################################################################
- # #
- # clive's carpets #
- # admin menu #
- # #
- # #
- # 1 - add a new user #
- # 2 - exit #
- # #
- ################################################################################
- """)
- adminmenu = input("\nWhat option would you like to chose? 1 or 2?: \n")
- while True:
- if adminmenu == "1":
- newuser()
- break
- elif adminmenu == "2":
- mainmenu()
- break
- def usermenu():
- print("""
- ################################################################################
- # #
- # clive's carpets #
- # user menu #
- # #
- ################################################################################
- """)
- def newuser():
- usertype, username, password1, password2 = "", "", "", ""
- while True:
- usertype = input("what type of user are you creating\n(1)Admin \n(2)User\nType -1 to exit to the mainn menu\n")
- if usertype == "-1":
- mainmenu()
- if len(usertype) > 1:
- print("\ninvalid input!\n")
- elif usertype.isdigit() != True:
- print("\nplease enter a number: \n")
- elif int (usertype) <1:
- print("\ninvalid input!\n")
- elif int (usertype) >2:
- print("\ninvalid input!\n")
- else:
- break
- while True:
- username = input("\nEnter the name of new user: \n")
- if username == "-1":
- mainmenu()
- if len (username) > 10:
- print ("\nusermane must be less than 11 chars: \n")
- elif username.isalpha() == False:
- print ("\nthe usermane must contain alpha!\n")
- else:
- break
- while True:
- password1 = input("what is your password?\n")
- if password1 == "-1":
- mainmenu()
- if len (password1) >10:
- print ("\npassword must be less than 11 chars: \n")
- password2 = input("AGAIN!\n")
- if password2 == "-1":
- mainmenu()
- if len (password2) >10:
- print ("\npassword must be less than 11 chars: \n")
- if password1 != password2:
- print ("\npassword does not match: \n")
- else:
- break
- username = username.lower()
- password1 = password1.lower()
- password2 = password2.lower()
- usertypestore = str(usertype).ljust(1)
- usernamestore = username.ljust(10)
- passwordstore = password1.ljust(10)
- store = open ("users.txt","a")
- istore = usernamestore + passwordstore + usertypestore + "\n"
- store.write(istore)
- store.close()
- print("\nNew user added: ")
- print("usertype: ",usertype)
- print("username: ",username)
- print("Password: *********")
- def validateuser():
- validateusertype, validateusername, validatepassword = "","",""
- username = str(input("\nplease enter your username: \n"))
- password = str(input("\nplease enter your password: \n"))
- while True:
- try:
- readusers = open("users.txt","r")
- validatecounter = 0
- while True:
- location = readusers.readline()
- validateusertype = location[20:21]
- validateusertype = validateusertype.strip()
- validateusername = location[0:10]
- validateusername = validateusername.strip()
- validateusername = validateusername.lower()
- username = username.lower()
- validatepassword = location[10:20]
- validatepassword = validatepassword.strip()
- validatepassword = validatepassword.lower()
- if location == "":
- readusers.close()
- break
- if validateusertype == str(1) and validateusername == username and validatepassword == password:
- validatecounter = validatecounter + 1
- adminmenu()
- break
- if validateusertype == str(2) and validateusername == username and validatepassword == password:
- validatecounter = validatecounter + 1
- usermenu()
- break
- if validatecounter == 0:
- print ("\nNo user in file with login details\n")
- validateuser()
- except FileNotFoundError:
- print("\nthere is no user file to search. How about making a new account? \n")
- newuser()
- def main():
- mainmenu()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement