from hashlib import sha256
import random, sys
def hash(string):
'''Hashes a string'''
return sha256(
string.encode()).hexdigest() # when using hash() returns a hashed string
def save_users():
f = open("UserDetails.txt", "w")
f.write("Username;{} \nPassword:{}".format(username, password))
f.close
print("\nWelcome")
signIn = input("Do you have an account? [Y/N]").upper()
if signIn == "N":
print("Sign up :")
username = input("New Username: ")
password = hash(input("New Password: "))
confirm = hash(input("ConfirmPassword: ")) == password
print(password)
if not confirm:
print("Passwords do not match")
save_users()
"print (password)" is just there for me to test if it actually hashed the string as this is my first time doing anything like this. How would I save the password and username to an email, and similarly how would I authenticate the password and username?
Python 3.8.5
>Solution :
Replace:
def save_users():
f = open("UserDetails.txt", "w")
f.write("Username;{} \nPassword:{}".format(username, password))
f.close
With:
def save_users(username, password):
f = open("UserDetails.txt", "w")
f.write("Username;{} \nPassword:{}".format(username, password))
f.close()
And call it with save_users(username, password) instead of save_users()