i am trying to implement a encryption into my login program, i've looked for help in many places but i can't seem to understand any of it. Im fairly new to python and im warming up for a university course in it. im interested in if it is possible to implement it as a class in my already excisting program, any tips or explanations would be greatly appreciated
So basicly what im asking is, how would it look if i wanted the program to encrypt the passwords between runs and the decrypt them again so that the program can use them when it runs.
Program:
import json
with open("login_data.txt", "r") as login_file:
try:
users = json.load(login_file)
except:
users = {}
status = ""
def Display_Menu():
status = input("Are you a registered user? (y/n)? Press q to quit: ")
if status == "y":
Old_User()
elif status == "n":
New_User()
elif status == "passwd":
Change_Passwd()
elif status == "q":
skriva = open("login_data.txt", "w")
json.dump(users, skriva)
return status
def New_User():
Create_Login =input("Create login name: ")
if Create_Login in users:
print ("Login name already exist!")
else:
Create_Password =input("Create password: ")
users[Create_Login] = Create_Password
print("New User created!")
current_user = None
def Old_User():
global current_user
login =input("Enter login name: ")
Password =input("Enter password: ")
if login in users and users[login] == Password:
print("Login successful!")
current_user = login
status = input("Wanna quit, change pass, och logout?")
if status == "passwd":
Change_Passwd()
elif status == "logout":
Display_Menu()
elif status == "q":
skriva = open("login_data.txt", "w")
json.dump(users, skriva)
return status
else:
print("User doesn't exist or wrong password!")
def Change_Passwd():
oldpass =input("Old password: ")
if current_user in users and users[current_user] == oldpass:
Create_Password = input("New password: ")
users[current_user] = Create_Password
if Create_Password == input("Confirm password: "):
print("Password changed!")
else:
print("User authorization failure")
users[current_user] = oldpass
else:
print ("No password match!")
while status != "q":
status = Display_Menu()