Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #open a file in read mode
- file = open("data.txt","r")
- #read each line of data to a vairble
- FileData = file.readlines()
- #close the file
- file.close()
- #set correct password to false as no true password found yet
- CorrectPassword = False
- while CorrectPassword == False:
- #ask the user for username and password
- print("input your username?")
- UserName = input()
- print("input your password?")
- UserPassword = input()
- #go through each line of the file
- for line in FileData:
- #split the line in to first and second section
- LineUserName = line.split(":")[0]
- LineUserPassword = line.split(":")[1]
- #check if the username is the same as the one in this line
- if UserName == LineUserName :
- #now check if thepassword is correct
- if UserPassword == LineUserPassword:
- CorrectPassword=True
- if CorrectPassword == False:
- print("Your usernam or password is incorrect")
- print("")
- print("This is a secret message")
- print("choose an option: 1 - Add user ,2 - delete user , 3 - change password")
- UserChoice = input()
- if UserChoice == "1":
- PassMatch = False
- while PassMatch == False:
- print("please type the new username")
- NewUserName = input()
- print("please type the new password")
- NewUserPassword = input()
- print("please retype the new password")
- PasswordCheck = input()
- if NewUserPassword == PasswordCheck:
- PassMatch=True
- else:
- print("passwords don't match")
- file = open("data.txt","a")
- print("\n" + NewUserName+ ":" + NewUserPassword)
- file.write("\n" + NewUserName+ ":" + NewUserPassword)
- file.close()
- elif UserChoice == "2":
- print("please type the user name of the user to remove?")
- UserName=input()
- file = open("data.txt","r")
- FileData = file.readlines()
- file.close()
- file = open("data.txt","w")
- for line in FileData:
- LineUserName = line.split(":")[0]
- LineUserPassword = line.split(":")[1]
- if Uername != LineUserName :
- file.write(line)
- file.close()
- if UserChoice == "3":
- PassMatch = False
- while PassMatch== False:
- print("please type the new password")
- NewUserPassword = input()
- print("please retype the new password")
- PasswordCheck = input()
- if NewUserPassword == PasswordCheck:
- PassMatch=True
- else:
- print("passwords don't match")
- file = open("data.txt","r")
- FileData = file.readlines()
- file.close()
- file = open("data.txt","w")
- LineNumber+ 0
- for line in FileData:
- LineUserName = line.split(":")[0]
- LineUserPassword = line.split(":")[1]
- if Uername != LineUserName :
- file.write(LineUserName + ":" + LinePassword + ":")
- else:
- file.write("\n"+ LineUserName + ":" + LinePassword + ":")
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement