Answer the question
In order to leave comments, you need to log in
Password hash and salt to file?
I have already made a hash and salt generator and writing to the document, now you need to check the hash and password that you entered from the document, the variable with the hash (Exactly with the one in the file.) I can’t do it, I don’t know how.
Code:
from tkinter import *
from tkinter import messagebox
import tkinter as tk
import pickle
import hashlib, uuid
root = Tk()
root.geometry("300x300")
# root.geometry("300x500")
root.title("Login panel")
root.resizable(width=False, height=False)
Tag1 = Label(text="Login Panel By SANTIK", fg='#0c0')
Tag1.pack()
SEPARATOR = "&"
# generate hash string with salt
def gen_hash(pwd, salt):
return hashlib.sha512((pwd + salt).encode('utf-8')).hexdigest()
# generage hash password string (for safe to file)
def gen_pw_string(pwd):
salt = uuid.uuid4().hex
return salt + SEPARATOR + gen_hash(pwd, salt)
# parse hash password string, split it by salt and password hash
def parse_pw_string(pwstring):
return pwstring.split(SEPARATOR)
# check password by its password hash string
def check_pwd(pwd, pwstring):
salt, _pwhash = parse_pw_string(pwstring)
pwhash = gen_hash(pwd, salt)
return pwhash == _pwhash
def registration():
reg_win = Toplevel(root)
reg_win.geometry("300x300")
reg_win.title("Login panel")
reg_win.resizable(width=False, height=False)
Tag2 = Label(reg_win, text="Login Panel By SANTIK", fg='#0c0')
text_log = Label(reg_win,text="Введите ваш логин:")
registr_login = Entry(reg_win, )
text_password1 = Label(reg_win, text="Введите ваш пароль:")
registr_password1 = Entry(reg_win, )
text_password2 = Label(reg_win, text="Подтвердите пароль:")
registr_password2 = Entry(reg_win, show="")
button_registr = Button(reg_win, text="Зарегестрироваться!", command=lambda: save())
text_log1 = Label(reg_win, text="Пароли не совпадают!", fg='#f00')
text_ntv = Label(reg_win, text="Поля не могут быть пустыми!", fg='#f00')
Tag2.pack()
text_log.pack()
registr_login.pack()
text_password1.pack()
registr_password1.pack()
text_password2.pack()
registr_password2.pack()
button_registr.pack()
def des_but(object):
object.config(state='disabled')
def save():
if registr_password2.get() == "":
text_log1.place(relx=-5, rely=0)
text_ntv.pack()
elif registr_password1.get() == "":
text_log1.place(relx=-5, rely=0)
text_ntv.pack()
elif registr_login.get() == "":
text_log1.place(relx=-5, rely=0)
text_ntv.pack()
else:
if registr_password2.get() == registr_password1.get():
des_but(button_registr)
des_but(button_reg)
text_log1.destroy()
text_ntv.destroy()
text_log = Label(reg_win, text="Поздравляем! Теперь вы можите закрыть это окно!")
text_log.pack()
login_pass_save = {}
pwd1 = registr_login.get()
pwd2 = registr_password1.get()
pwstring1 = gen_pw_string(pwd1)
pwstring2 = gen_pw_string(pwd2)
print(pwd1, pwstring1)
print(pwd2, pwstring2)
print(check_pwd(pwd1, pwstring1))
print(check_pwd(pwd2, pwstring2))
login_pass_save[pwstring1]=pwstring2
f = open("login.txt", "wb")
pickle.dump(login_pass_save, f)
f.close()
else:
text_ntv.place(relx=-5, rely=0)
text_log1.pack()
def login():
log_win = Toplevel(root)
log_win.geometry("300x300")
log_win.title("Login panel")
log_win.resizable(width=False, height=False)
Tag3 = Label(log_win, text="Login Panel By SANTIK", fg='#0c0')
text_enter_login = Label(log_win, text="Введите ваш логин:")
enter_login = Entry(log_win, )
text_enter_pass = Label(log_win, text="Введите ваш пароль:")
enter_password= Entry(log_win, show="*")
button_enter = Button(log_win, text='Войти', command=lambda: log_pass())
Tag3.pack()
text_enter_login.pack()
enter_login.pack()
text_enter_pass.pack()
enter_password.pack()
button_enter.pack()
def toggle_password():
if enter_password.cget('show') == '':
enter_password.config(show='*')
toggle_btn.config(text='Показать пароль')
else:
enter_password.config(show='')
toggle_btn.config(text='Спрятать пароль')
toggle_btn = tk.Button(log_win, text='Показать пароль', width=20, command=toggle_password)
toggle_btn.pack
def log_pass():
f = open("login.txt", "rb")
a = pickle.load(f)
f.close()
pwd1 = enter_login.get()
pwd2 = enter_password.get()
pwstring1 = gen_pw_string(pwd1)
pwstring2 = gen_pw_string(pwd2)
print(pwd1, pwstring1)
print(pwd2, pwstring2)
print(check_pwd(pwd1, pwstring1))
print(check_pwd(pwd2, pwstring2))
if check_pwd(enter_login.get(), pwstring1) == ("True"):
if check_pwd(enter_password.get(), pwstring2) == ("True"):
messagebox.showinfo("Вход выполнен!","Вход успешный! Поздравляю!")
else:
messagebox.showerror("Ошибка входа!", "Логин или пароль не верный! Проверте их на наличие ошибки!")
else:
messagebox.showerror("Ошибка входа!","Логин или пароль не верный! Проверте их на наличие ошибки!")
button_reg = Button(root, height=10, width=18, text="Зарегистрироваться!", command=registration)
button_reg.place(x=5, y=50)
button_log = Button(root, height=10, width=18, text="Войти!", command=login)
button_log.place(x=150, y=50)
root.mainloop()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question