reformat
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2021-04-18 13:36:04 +02:00
parent c5533e1c5e
commit cb929266cd
Signed by: tormakris
GPG Key ID: DC83C4F2C41B1047
2 changed files with 13 additions and 19 deletions

View File

@ -1,4 +1,4 @@
import os,sys
import os, sys
from base64 import b64encode
from Crypto.Hash import SHA256
from Crypto.Protocol.KDF import bcrypt, bcrypt_check
@ -9,10 +9,11 @@ import logging
auth_logger = logging.getLogger('AUTH APPLICATION ')
auth_logger.root.setLevel(logging.INFO)
class Authetication:
ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
HOME_DIRECTORY_LOCATION = ABSOLUTE_PATH + "\\home"
CONFIG_DIRECTORY_LOCATION = ABSOLUTE_PATH+ "\\config"
CONFIG_DIRECTORY_LOCATION = ABSOLUTE_PATH + "\\config"
USER_INDEX = 0
def __init__(self):
@ -22,14 +23,14 @@ class Authetication:
if not os.path.isdir(self.CONFIG_DIRECTORY_LOCATION):
os.mkdir(self.CONFIG_DIRECTORY_LOCATION)
if not os.path.isfile(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt") or os.stat(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt").st_size == 0:
if not os.path.isfile(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt") or os.stat(
self.CONFIG_DIRECTORY_LOCATION + "\\config.txt").st_size == 0:
data = {}
data['index'] = 0
data['user'] = []
with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
json.dump(data, outfile)
def login(self, username, password):
with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
data = json.load(json_file)
@ -43,10 +44,9 @@ class Authetication:
except ValueError:
auth_logger.debug("User NOT logged in: " + username)
return ''
auth_logger.debug("User logged in: "+username)
auth_logger.debug("User logged in: " + username)
return user['homeDir']
def checkUserExists(self, username):
with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
data = json.load(json_file)
@ -57,16 +57,13 @@ class Authetication:
return False
def initConfig(self):
data = {}
data['index'] = 0
data['user'] = []
data = {'index': 0, 'user': []}
with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
json.dump(data, outfile)
shutil.rmtree(self.HOME_DIRECTORY_LOCATION)
os.mkdir(self.HOME_DIRECTORY_LOCATION)
def saveUser(self, username, password):
bytePass = password.encode('utf-8')
b64pwd = b64encode(SHA256.new(bytePass).digest())
@ -78,7 +75,7 @@ class Authetication:
user = {
'username': username,
'password': bcrypt_hash.decode('utf-8'),
'homeDir': data['index']+1
'homeDir': data['index'] + 1
}
data['index'] = data['index'] + 1
@ -97,7 +94,3 @@ class Authetication:
auth_logger.debug("User NOT saved! Home directory already exists")
return True

View File

@ -2,10 +2,10 @@ from authentication import Authetication
import json
import logging
test_logger = logging.getLogger('TEST ')
test_logger.root.setLevel(logging.INFO)
def testSaveUser(username, password):
logging.info('STARTING SAVE USER TEST')
auth = Authetication()
@ -61,7 +61,8 @@ def testUserExists(username, password):
else:
logging.info('TEST 2 --> User exists with INVALID user :: PASSED')
if __name__ == '__main__':
testSaveUser("Diósbejglia","Diósbejgli")
testAuth("Diósbejglia","Diósbejgli")
testUserExists("Diósbejglia","Diósbejgli")
testSaveUser("Diósbejglia", "Diósbejgli")
testAuth("Diósbejglia", "Diósbejgli")
testUserExists("Diósbejglia", "Diósbejgli")