Advertisement
mfx28

Untitled

Jun 9th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. def registo(numaluno, password):
  2.     found = False
  3.     with open("Accounts.txt", "r+") as file:
  4.         for line in file:
  5.             user, pw = line.split(":")
  6.             if numaluno == user:
  7.                 print("O utilizador",numaluno,"já existe")
  8.                 found = True
  9.     file.close()
  10.     if found == True:
  11.         mudarpw = input("Pretende alterar a password? [S/N]: ")
  12.         if mudarpw == "s" or mudarpw == "S":
  13.             output = ""
  14.             while True:
  15.                 password = input("Insira a nova password: ")
  16.                 if validarPW(password):
  17.                     for line in fileinput.input(["Accounts.txt"], inplace=True):
  18.                         if line.strip().startswith(numaluno):
  19.                             line = numaluno+":"+password+"\n"
  20.                         output = output + line
  21.                     f = open("Accounts.txt", "w")
  22.                     f.write(output)
  23.                     f.close()
  24.                     print ("Alterada com sucesso")
  25.                     break
  26.  
  27.     if not found:
  28.         with open("Accounts.txt", "a+") as file:
  29.             account = '\n%s:%s'%(numaluno,password)
  30.             file.write(account)
  31.             print ('O utilizador foi guardado com sucesso')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement