change user password func

This commit is contained in:
Spekulaas
2023-10-25 17:09:07 +02:00
parent dabea47437
commit c14a360418
6 changed files with 87 additions and 46 deletions

View File

@@ -62,12 +62,12 @@ class DatabaseHelper:
print(error)
return False
def changePasswordUser(self, user_privatekey, password):
def changePassword(self, user_privatekey, old_password, password):
if not self.conn:
return None
try:
self.cursor.execute("UPDATE `users` SET `password` = ? WHERE `private_key` = ?", (password, user_privatekey,))
self.cursor.execute("UPDATE `users` SET `password` = ? WHERE (`private_key` = ? AND `password` = ?)", (password, user_privatekey, old_password,))
self.commit()
return True

View File

@@ -44,7 +44,7 @@ class MenuHelper:
self.user_settings_menu[1] = "View account info"
self.user_settings_menu[2] = "Change username"
self.user_settings_menu[3] = "Change password"
self.user_settings_menu[3] = "DELETE ACCOUNT"
self.user_settings_menu[4] = "DELETE ACCOUNT"
self.opened_logs = False
@@ -106,7 +106,7 @@ class MenuHelper:
user = None
case "User Settings":
print(user.private_key)
self.runUserSettingsMenu(user)
case "Blockchain":
self.runUserBlockchainMenu(user)
@@ -167,7 +167,7 @@ class MenuHelper:
print("TODO")
case "Change password":
print("TODO")
user.updatePassword()
case "DELETE ACCOUNT":
print("TODO")

View File

@@ -0,0 +1,40 @@
from cryptography.exceptions import *
from cryptography.hazmat.primitives.asymmetric import rsa
from cryptography.hazmat.primitives import serialization
def generateKeys():
private_key = rsa.generate_private_key(public_exponent=65537,key_size=2048)
public_key = private_key.public_key()
return private_key, public_key
def keysToBytes(private_key, public_key):
prv_ser = privateKeyToBytes(private_key)
pbc_ser = publicKeyToBytes(public_key)
return prv_ser, pbc_ser
def publicKeyToBytes(public_key):
pbc_ser = public_key.public_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo)
return pbc_ser
def privateKeyToBytes(private_key):
prv_ser = private_key.private_bytes(
encoding=serialization.Encoding.PEM,
format=serialization.PrivateFormat.TraditionalOpenSSL,
encryption_algorithm=serialization.NoEncryption())
return prv_ser
def bytesToKeys(private_ser, public_ser):
private_key = serialization.load_pem_private_key(
private_ser,
password=None
)
public_key = serialization.load_pem_public_key(
public_ser
)
return private_key, public_key

View File

@@ -0,0 +1,10 @@
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
import hashlib
def computeHash(data):
hash = hashlib.sha256()
data = str(data).encode()
hash.update(data)
return hash.hexdigest()