diff --git a/server/authentication.py b/server/authentication.py index 6c68cc2..5d6cb51 100644 --- a/server/authentication.py +++ b/server/authentication.py @@ -11,6 +11,7 @@ from Crypto.Hash import SHA256 from Crypto.Protocol.KDF import bcrypt, bcrypt_check from Crypto.PublicKey import RSA from Crypto.PublicKey.RSA import RsaKey +from Crypto.Random import get_random_bytes auth_logger = logging.getLogger('AUTH APPLICATION ') auth_logger.setLevel(logging.INFO) @@ -82,9 +83,10 @@ class Authetication: def saveUser(self, username: str, password: str) -> bool: + user_salt = get_random_bytes(16) bytePass = password.encode('utf-8') b64pwd = b64encode(SHA256.new(bytePass).digest()) - bcrypt_hash = bcrypt(b64pwd, 12) + bcrypt_hash = bcrypt(password=b64pwd, cost=12, salt=user_salt) with open(self.CONFIG_FILE_LOCATION) as json_file: data = json.load(json_file) diff --git a/server/authentication_test.py b/server/authentication_test.py index 1f5a161..edd81a9 100644 --- a/server/authentication_test.py +++ b/server/authentication_test.py @@ -35,7 +35,7 @@ def testAuth(username: str, password: str): auth.saveUser(username, password) homeDir = auth.login(username, password) - if homeDir == '1': + if homeDir == auth.HOME_DIRECTORY_LOCATION + os.path.sep + '1': test_logger.info('TEST 1 --> Authentication test with VALID :: PASSED') else: test_logger.info('TEST 1 --> Authentication test with VALID :: FAILED') @@ -118,4 +118,4 @@ if __name__ == '__main__': testSaveUser("Diósbejglia", "Diósbejgli") testAuth("Diósbejglia", "Diósbejgli") testUserExists("Diósbejglia", "Diósbejgli") - testPersistency() + #testPersistency()