merged functions for master password hashing
This commit is contained in:
parent
a5d93f0d5c
commit
baef759929
@ -31,9 +31,7 @@ def add_record(
|
||||
|
||||
master_salt, hash_pass = master_password_from_db
|
||||
if (
|
||||
cryptography.master_pass.encrypt_master_pass_known_salt(
|
||||
master_password, master_salt
|
||||
)
|
||||
cryptography.master_pass.encrypt_master_pass(master_password, master_salt)
|
||||
!= hash_pass
|
||||
):
|
||||
return _send_tmp_message(bot, mes.chat.id, "Не подходит главный пароль")
|
||||
@ -107,10 +105,7 @@ def get_account(
|
||||
if data[1] not in database.get.get_accounts(engine, mes.from_user.id):
|
||||
return _send_tmp_message(bot, mes.chat.id, "Нет такого аккаунта")
|
||||
|
||||
if (
|
||||
cryptography.master_pass.encrypt_master_pass_known_salt(data[2], master_salt)
|
||||
!= hash_pass
|
||||
):
|
||||
if cryptography.master_pass.encrypt_master_pass(data[2], master_salt) != hash_pass:
|
||||
return _send_tmp_message(bot, mes.chat.id, "Не подходит главный пароль")
|
||||
|
||||
salt, enc_login, enc_pass = database.get.get_account_info(
|
||||
|
@ -1,12 +1,26 @@
|
||||
from typing import overload
|
||||
|
||||
import bcrypt
|
||||
|
||||
|
||||
@overload
|
||||
def encrypt_master_pass(passwd: str, salt: bytes) -> bytes:
|
||||
...
|
||||
|
||||
|
||||
@overload
|
||||
def encrypt_master_pass(passwd: str) -> tuple[bytes, bytes]:
|
||||
...
|
||||
|
||||
|
||||
def encrypt_master_pass(
|
||||
passwd: str, salt: bytes | None = None
|
||||
) -> tuple[bytes, bytes] | bytes:
|
||||
"""Hashes master password and return tuple of hashed password and salt"""
|
||||
salt = bcrypt.gensalt()
|
||||
if salt is None:
|
||||
salt = bcrypt.gensalt()
|
||||
gened_salt = True
|
||||
else:
|
||||
gened_salt = False
|
||||
hashed = bcrypt.hashpw(passwd.encode("utf-8"), salt)
|
||||
return (hashed, salt)
|
||||
|
||||
|
||||
def encrypt_master_pass_known_salt(passwd: str, salt: bytes) -> bytes:
|
||||
return bcrypt.hashpw(passwd.encode("utf-8"), salt)
|
||||
return (hashed, salt) if gened_salt else hashed
|
||||
|
Reference in New Issue
Block a user