Advertisement
Guest User

Untitled

a guest
Apr 20th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. #open a file in read mode
  2. file = open("data.txt","r")
  3. #read each line of data to a vairble
  4. FileData = file.readlines()
  5. #close the file
  6. file.close()
  7. #set correct password to false as no true password found yet
  8. CorrectPassword = False
  9. while CorrectPassword == False:
  10.     #ask the user for username and password
  11.     print("input your username?")
  12.     UserName = input()
  13.     print("input your password?")
  14.     UserPassword = input()
  15.     #go through each line of the file
  16.     for line in  FileData:
  17.         #split the line in to first and second section
  18.         LineUserName = line.split(":")[0]
  19.         LineUserPassword = line.split(":")[1]
  20.         #check if the username is the same as the one in this line
  21.         if  UserName == LineUserName :
  22.             #now check if thepassword is correct
  23.             if UserPassword == LineUserPassword:
  24.                 CorrectPassword=True
  25.         if CorrectPassword == False:
  26.             print("Your usernam or password is incorrect")
  27.             print("")
  28. print("This is a secret message")
  29.  
  30. print("choose an option: 1 - Add user ,2 - delete user ,  3 - change password")
  31. UserChoice = input()
  32. if UserChoice == "1":
  33.     PassMatch = False
  34.     while PassMatch == False:
  35.         print("please type the new username")
  36.         NewUserName = input()
  37.         print("please type the new password")
  38.         NewUserPassword = input()
  39.         print("please retype the new password")
  40.         PasswordCheck = input()
  41.         if NewUserPassword == PasswordCheck:
  42.             PassMatch=True
  43.         else:
  44.             print("passwords don't match")
  45.     file = open("data.txt","a")
  46.     print("\n" + NewUserName+ ":" +  NewUserPassword)
  47.     file.write("\n" + NewUserName+ ":" +  NewUserPassword)
  48.     file.close()
  49. elif UserChoice == "2":
  50.      print("please type the user name of the user to remove?")
  51.      UserName=input()
  52.      file = open("data.txt","r")
  53.      FileData = file.readlines()
  54.      file.close()
  55.      file = open("data.txt","w")
  56.      for line in FileData:
  57.           LineUserName = line.split(":")[0]
  58.           LineUserPassword = line.split(":")[1]
  59.           if Uername != LineUserName :
  60.               file.write(line)
  61.      file.close()
  62. if UserChoice == "3":
  63.     PassMatch = False
  64.     while PassMatch== False:
  65.         print("please type the new password")
  66.         NewUserPassword = input()
  67.         print("please retype the new password")
  68.         PasswordCheck = input()
  69.         if NewUserPassword == PasswordCheck:
  70.             PassMatch=True
  71.         else:
  72.             print("passwords don't match")
  73.     file = open("data.txt","r")
  74.     FileData = file.readlines()
  75.     file.close()
  76.     file = open("data.txt","w")
  77.     LineNumber+ 0
  78.     for line in FileData:
  79.         LineUserName = line.split(":")[0]
  80.         LineUserPassword = line.split(":")[1]
  81.         if Uername != LineUserName :
  82.             file.write(LineUserName + ":" + LinePassword + ":")
  83.         else:
  84.             file.write("\n"+ LineUserName + ":" + LinePassword + ":")
  85.     file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement