This commit is contained in:
parent
6d2441d931
commit
18bfac4a86
@ -11,6 +11,7 @@ from Crypto.Hash import SHA256
|
|||||||
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
|
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
|
||||||
from Crypto.PublicKey import RSA
|
from Crypto.PublicKey import RSA
|
||||||
from Crypto.PublicKey.RSA import RsaKey
|
from Crypto.PublicKey.RSA import RsaKey
|
||||||
|
from Crypto.Random import get_random_bytes
|
||||||
|
|
||||||
auth_logger = logging.getLogger('AUTH APPLICATION ')
|
auth_logger = logging.getLogger('AUTH APPLICATION ')
|
||||||
auth_logger.setLevel(logging.INFO)
|
auth_logger.setLevel(logging.INFO)
|
||||||
@ -82,9 +83,10 @@ class Authetication:
|
|||||||
|
|
||||||
|
|
||||||
def saveUser(self, username: str, password: str) -> bool:
|
def saveUser(self, username: str, password: str) -> bool:
|
||||||
|
user_salt = get_random_bytes(16)
|
||||||
bytePass = password.encode('utf-8')
|
bytePass = password.encode('utf-8')
|
||||||
b64pwd = b64encode(SHA256.new(bytePass).digest())
|
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:
|
with open(self.CONFIG_FILE_LOCATION) as json_file:
|
||||||
data = json.load(json_file)
|
data = json.load(json_file)
|
||||||
|
@ -35,7 +35,7 @@ def testAuth(username: str, password: str):
|
|||||||
auth.saveUser(username, password)
|
auth.saveUser(username, password)
|
||||||
homeDir = auth.login(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')
|
test_logger.info('TEST 1 --> Authentication test with VALID :: PASSED')
|
||||||
else:
|
else:
|
||||||
test_logger.info('TEST 1 --> Authentication test with VALID :: FAILED')
|
test_logger.info('TEST 1 --> Authentication test with VALID :: FAILED')
|
||||||
@ -118,4 +118,4 @@ if __name__ == '__main__':
|
|||||||
testSaveUser("Diósbejglia", "Diósbejgli")
|
testSaveUser("Diósbejglia", "Diósbejgli")
|
||||||
testAuth("Diósbejglia", "Diósbejgli")
|
testAuth("Diósbejglia", "Diósbejgli")
|
||||||
testUserExists("Diósbejglia", "Diósbejgli")
|
testUserExists("Diósbejglia", "Diósbejgli")
|
||||||
testPersistency()
|
#testPersistency()
|
||||||
|
Loading…
Reference in New Issue
Block a user