diff --git a/solvable/src/webservice/crypto.py b/solvable/src/webservice/crypto.py index ff050a4..8bd034b 100644 --- a/solvable/src/webservice/crypto.py +++ b/solvable/src/webservice/crypto.py @@ -3,17 +3,22 @@ from hashlib import scrypt class PasswordHasher: - @staticmethod - def hash(password): - salt = urandom(32) - return PasswordHasher.scrypt(password, salt).hex()+salt.hex() + n = 16384 + r = 8 + p = 1 + dklen = 32 - @staticmethod - def verify(password, salted_hash): + @classmethod + def hash(cls, password): + salt = urandom(32) + return cls.scrypt(password, salt).hex() + salt.hex() + + @classmethod + def verify(cls, password, salted_hash): salt = bytes.fromhex(salted_hash)[32:] hashdigest = bytes.fromhex(salted_hash)[:32] - return PasswordHasher.scrypt(password, salt) == hashdigest + return cls.scrypt(password, salt) == hashdigest - @staticmethod - def scrypt(password, salt): - return scrypt(password.encode(), salt=salt, n=16384, r=8, p=1, dklen=32) + @classmethod + def scrypt(cls, password, salt): + return scrypt(password.encode(), salt=salt, n=cls.n, r=cls.r, p=cls.p, dklen=cls.dklen)