Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def registo(numaluno, password):
- found = False
- with open("Accounts.txt", "r+") as file:
- for line in file:
- user, pw = line.split(":")
- if numaluno == user:
- print("O utilizador",numaluno,"já existe")
- found = True
- file.close()
- if found == True:
- mudarpw = input("Pretende alterar a password? [S/N]: ")
- if mudarpw == "s" or mudarpw == "S":
- output = ""
- while True:
- password = input("Insira a nova password: ")
- if validarPW(password):
- for line in fileinput.input(["Accounts.txt"], inplace=True):
- if line.strip().startswith(numaluno):
- line = numaluno+":"+password+"\n"
- output = output + line
- f = open("Accounts.txt", "w")
- f.write(output)
- f.close()
- print ("Alterada com sucesso")
- break
- if not found:
- with open("Accounts.txt", "a+") as file:
- account = '\n%s:%s'%(numaluno,password)
- file.write(account)
- print ('O utilizador foi guardado com sucesso')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement