This commit is contained in:
		@@ -9,6 +9,7 @@ import logging
 | 
				
			|||||||
auth_logger = logging.getLogger('AUTH APPLICATION ')
 | 
					auth_logger = logging.getLogger('AUTH APPLICATION ')
 | 
				
			||||||
auth_logger.root.setLevel(logging.INFO)
 | 
					auth_logger.root.setLevel(logging.INFO)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Authetication:
 | 
					class Authetication:
 | 
				
			||||||
    ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
 | 
					    ABSOLUTE_PATH = os.path.abspath(os.path.dirname(sys.argv[0]))
 | 
				
			||||||
    HOME_DIRECTORY_LOCATION = ABSOLUTE_PATH + "\\home"
 | 
					    HOME_DIRECTORY_LOCATION = ABSOLUTE_PATH + "\\home"
 | 
				
			||||||
@@ -22,14 +23,14 @@ class Authetication:
 | 
				
			|||||||
        if not os.path.isdir(self.CONFIG_DIRECTORY_LOCATION):
 | 
					        if not os.path.isdir(self.CONFIG_DIRECTORY_LOCATION):
 | 
				
			||||||
            os.mkdir(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 = {}
 | 
				
			||||||
            data['index'] = 0
 | 
					            data['index'] = 0
 | 
				
			||||||
            data['user'] = []
 | 
					            data['user'] = []
 | 
				
			||||||
            with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
 | 
					            with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
 | 
				
			||||||
                json.dump(data, outfile)
 | 
					                json.dump(data, outfile)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def login(self, username, password):
 | 
					    def login(self, username, password):
 | 
				
			||||||
        with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
					        with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
				
			||||||
            data = json.load(json_file)
 | 
					            data = json.load(json_file)
 | 
				
			||||||
@@ -46,7 +47,6 @@ class Authetication:
 | 
				
			|||||||
        auth_logger.debug("User logged in: " + username)
 | 
					        auth_logger.debug("User logged in: " + username)
 | 
				
			||||||
        return user['homeDir']
 | 
					        return user['homeDir']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def checkUserExists(self, username):
 | 
					    def checkUserExists(self, username):
 | 
				
			||||||
        with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
					        with open(Authetication.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
				
			||||||
            data = json.load(json_file)
 | 
					            data = json.load(json_file)
 | 
				
			||||||
@@ -57,16 +57,13 @@ class Authetication:
 | 
				
			|||||||
        return False
 | 
					        return False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def initConfig(self):
 | 
					    def initConfig(self):
 | 
				
			||||||
        data = {}
 | 
					        data = {'index': 0, 'user': []}
 | 
				
			||||||
        data['index'] = 0
 | 
					 | 
				
			||||||
        data['user'] = []
 | 
					 | 
				
			||||||
        with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
 | 
					        with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
 | 
				
			||||||
            json.dump(data, outfile)
 | 
					            json.dump(data, outfile)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        shutil.rmtree(self.HOME_DIRECTORY_LOCATION)
 | 
					        shutil.rmtree(self.HOME_DIRECTORY_LOCATION)
 | 
				
			||||||
        os.mkdir(self.HOME_DIRECTORY_LOCATION)
 | 
					        os.mkdir(self.HOME_DIRECTORY_LOCATION)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def saveUser(self, username, password):
 | 
					    def saveUser(self, username, password):
 | 
				
			||||||
        bytePass = password.encode('utf-8')
 | 
					        bytePass = password.encode('utf-8')
 | 
				
			||||||
        b64pwd = b64encode(SHA256.new(bytePass).digest())
 | 
					        b64pwd = b64encode(SHA256.new(bytePass).digest())
 | 
				
			||||||
@@ -97,7 +94,3 @@ class Authetication:
 | 
				
			|||||||
                auth_logger.debug("User NOT saved! Home directory already exists")
 | 
					                auth_logger.debug("User NOT saved! Home directory already exists")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            return True
 | 
					            return True
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,10 +2,10 @@ from authentication import Authetication
 | 
				
			|||||||
import json
 | 
					import json
 | 
				
			||||||
import logging
 | 
					import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
test_logger = logging.getLogger('TEST ')
 | 
					test_logger = logging.getLogger('TEST ')
 | 
				
			||||||
test_logger.root.setLevel(logging.INFO)
 | 
					test_logger.root.setLevel(logging.INFO)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def testSaveUser(username, password):
 | 
					def testSaveUser(username, password):
 | 
				
			||||||
    logging.info('STARTING SAVE USER TEST')
 | 
					    logging.info('STARTING SAVE USER TEST')
 | 
				
			||||||
    auth = Authetication()
 | 
					    auth = Authetication()
 | 
				
			||||||
@@ -61,6 +61,7 @@ def testUserExists(username, password):
 | 
				
			|||||||
    else:
 | 
					    else:
 | 
				
			||||||
        logging.info('TEST 2 --> User exists with INVALID user :: PASSED')
 | 
					        logging.info('TEST 2 --> User exists with INVALID user :: PASSED')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == '__main__':
 | 
					if __name__ == '__main__':
 | 
				
			||||||
    testSaveUser("Diósbejglia", "Diósbejgli")
 | 
					    testSaveUser("Diósbejglia", "Diósbejgli")
 | 
				
			||||||
    testAuth("Diósbejglia", "Diósbejgli")
 | 
					    testAuth("Diósbejglia", "Diósbejgli")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user