Değerli üstatlar merhaba. Accounts.py’de oluşturduğum kullanıcının parolasını sha256 ile şifreliyorum.
Örneğin ;
Accounts.py
test = UserRepository()
password = "123456"
convertShaPassword = GeneralSecure.SecurePassword.hash_password(password)
user = Account('0', 'Ahmet', 'BLOM', 'lisanne@gmail.com', 'Counselor', 'e', convertShaPassword, '0', '0')
test.accountRegister(user)
Oluşturmuş olduğum kullanıcının bu bilgilerini Database.py ile veritabanına gönderiyorum ;
Database.py
class AcceptVeriable:
def __init__(self):
self.accountList = []
with open("AccInformation.json", "r", encoding="utf-8") as file:
veriable = json.loads(file.read())
count = 0
while count < len(veriable):
self.accountList.append(veriable[count]['user_id'])
self.accountList.append(veriable[count]['firstName'])
self.accountList.append(veriable[count]['lastName'])
self.accountList.append(veriable[count]['username'])
self.accountList.append(veriable[count]['password'])
self.accountList.append(veriable[count]['email'])
self.accountList.append(veriable[count]['accessLevel'])
self.accountList.append(veriable[count]['accountKEY'])
self.accountList.append(veriable[count]['register_date'])
self.sendData()
self.accountList.clear()
count +=1
# Verileri veritabanına gönder
def sendData(self):
db = sqlite.connect("zyro.db")
im = db.cursor()
im.execute("""CREATE TABLE IF NOT EXISTS
staff_management(user_id, firstname, lastname,
username, password, email, access_level, acc_key, reg_date)""")
# Liste halinde tek seferde gönder.
transferToDB = self.accountList
im.execute("""INSERT INTO staff_management VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?)""", transferToDB)
db.commit()
# Json Dosyasında bekleyen verileri sil.
open('AccInformation.json', 'w').close()
Login.py ilede işte bildiğiniz gibi veritabanından bazı sorgulamalar yapıp (kullanıcı adı, şifre doğruluğu gibi) giriş yapılmasını sağlamak istiyorum.
Ancak ne yaptıysam yapayım başaramadım tek yönlü fonksiyon ile veriyi şifreledikten sonra ayarlayamadım girişi nasıl yapabileceğini.
Login.py
# Aktif Kullanıcı
def activeUser(self, username='[System]'):
self.username = username
return self.username
# TODO: Don't forget here, there will be a password query online // GERİ GEL BURAYI TAMAMEN GÜVENLİ HALE GETİR. + Admin şifre için Ayrı kontrol sınıfı oluştur.
def loginFunction(self):
data = sqlite.connect('zyro.db')
im = data.cursor()
self.txtUsername = self.tboxUserName.text() # Test
self.txtPassword = self.tboxPassword.text() # Test
im.execute("""SELECT username, password FROM staff_management WHERE
username = ? AND password = ?""", (self.txtUsername, self.txtPassword))
login = im.fetchone()
if login:
self.lblLoginSuccess.setText("Bilgiler doğrulandı, giriş sağlanıyor.")
self.WaitingPanel()
self.activeUser(self.txtUsername)
userRepo = UserRepository()
userRepo.IsLoggedIn = True
userRepo.currentUser = self.txtUsername
Login.transactionUser.append(self.txtUsername) # TODO: GERİ GEL BURAYI DETAYLANDIR.
Logs.JoinSystemLog(self.txtUsername) # Join Log
else:
self.lblLoginSuccess.setText("Bilgilerinizi tekrar kontrol edin...")
Bu konuda yardım edebilir misiniz lütfen ?
Ayrıca, şifreleme için kullandığım GeneralSecure.py :
import hashlib
import uuid
class SecurePassword:
def hash_password(password):
salt = uuid.uuid4().hex
return hashlib.sha256(salt.encode() + password.encode()).hexdigest() + ':' + salt
def check_password(hashed_password, user_password):
password, salt = hashed_password.split(':')
return password == hashlib.sha256(salt.encode() + user_password.encode()).hexdigest()
# new_pass = input('Please enter a password: ')
# hashed_password = hash_password(new_pass)
# print('The string to store in the db is: ' + hashed_password)
# old_pass = input('Now please enter the password again to check: ')
# if check_password(hashed_password, old_pass):
# print('You entered the right password')
# else:
# print('I am sorry but the password does not match')
Login.py’de bu girişi nasıl sağlayabilirim ? Şu örnekte ;
if check_password(hashed_password, old_pass):
şifrelenen veri ve girilen şifreyi parametre olarak vermiş evet ama Accounts.py’den bunları nasıl alabilirim ? Daha sonraki girişlerde problem olmayacak mı :S