This commit is contained in:
		@@ -9,6 +9,7 @@ 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"
 | 
			
		||||
@@ -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)
 | 
			
		||||
@@ -46,7 +47,6 @@ class Authetication:
 | 
			
		||||
        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())
 | 
			
		||||
@@ -97,7 +94,3 @@ class Authetication:
 | 
			
		||||
                auth_logger.debug("User NOT saved! Home directory already exists")
 | 
			
		||||
 | 
			
		||||
            return True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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,6 +61,7 @@ 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")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user