This commit is contained in:
		@@ -13,9 +13,10 @@ 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"
 | 
			
		||||
    PRIVATE_KEY_DIRECTORY_LOCATION = CONFIG_DIRECTORY_LOCATION + "\\private_keys"
 | 
			
		||||
    HOME_DIRECTORY_LOCATION = ABSOLUTE_PATH + os.path.sep +"home"
 | 
			
		||||
    CONFIG_DIRECTORY_LOCATION = ABSOLUTE_PATH + os.path.sep + "config"
 | 
			
		||||
    CONFIG_FILE_LOCATION = ABSOLUTE_PATH + os.path.sep + "config" + os.path.sep + "config.txt"
 | 
			
		||||
    PRIVATE_KEY_DIRECTORY_LOCATION = CONFIG_DIRECTORY_LOCATION + os.path.sep + "private_keys"
 | 
			
		||||
    USER_INDEX = 0
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
@@ -28,14 +29,14 @@ class Authetication:
 | 
			
		||||
        if not os.path.isdir(self.PRIVATE_KEY_DIRECTORY_LOCATION):
 | 
			
		||||
            os.mkdir(self.PRIVATE_KEY_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_FILE_LOCATION) or os.stat(
 | 
			
		||||
                self.CONFIG_FILE_LOCATION).st_size == 0:
 | 
			
		||||
            data = {'index': 0, 'user': []}
 | 
			
		||||
            with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
 | 
			
		||||
            with open(self.CONFIG_FILE_LOCATION, 'w+') as outfile:
 | 
			
		||||
                json.dump(data, outfile)
 | 
			
		||||
 | 
			
		||||
    def login(self, username: str, password: str) -> str:
 | 
			
		||||
        with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
        with open(self.CONFIG_FILE_LOCATION) as json_file:
 | 
			
		||||
            data = json.load(json_file)
 | 
			
		||||
 | 
			
		||||
        for user in data['user']:
 | 
			
		||||
@@ -51,7 +52,7 @@ class Authetication:
 | 
			
		||||
        return user['homeDir']
 | 
			
		||||
 | 
			
		||||
    def checkUserExists(self, username: str) -> bool:
 | 
			
		||||
        with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
        with open(self.CONFIG_FILE_LOCATION) as json_file:
 | 
			
		||||
            data = json.load(json_file)
 | 
			
		||||
 | 
			
		||||
        for user in data['user']:
 | 
			
		||||
@@ -61,7 +62,7 @@ class Authetication:
 | 
			
		||||
 | 
			
		||||
    def initConfig(self):
 | 
			
		||||
        data = {'index': 0, 'user': []}
 | 
			
		||||
        with open(self.CONFIG_DIRECTORY_LOCATION + "\\config.txt", 'w+') as outfile:
 | 
			
		||||
        with open(self.CONFIG_FILE_LOCATION, 'w+') as outfile:
 | 
			
		||||
            json.dump(data, outfile)
 | 
			
		||||
 | 
			
		||||
        shutil.rmtree(self.HOME_DIRECTORY_LOCATION)
 | 
			
		||||
@@ -72,7 +73,7 @@ class Authetication:
 | 
			
		||||
 | 
			
		||||
    def generatePrivateKeyForUser(self, username:str, user_passphrase:str, public_server_key='') -> bool:
 | 
			
		||||
        if self.checkUserExists(username):
 | 
			
		||||
            with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
            with open(self.CONFIG_FILE_LOCATION) as json_file:
 | 
			
		||||
                data = json.load(json_file)
 | 
			
		||||
 | 
			
		||||
            private_key = RSA.generate(2048)
 | 
			
		||||
@@ -89,7 +90,7 @@ class Authetication:
 | 
			
		||||
            for user in data['user']:
 | 
			
		||||
                if username == user['username']:
 | 
			
		||||
                    user['publicKey'] = public_key_value
 | 
			
		||||
                    with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt', 'w') as outfile:
 | 
			
		||||
                    with open(self.CONFIG_FILE_LOCATION, 'w') as outfile:
 | 
			
		||||
                        json.dump(data, outfile)
 | 
			
		||||
                    break
 | 
			
		||||
            return True
 | 
			
		||||
@@ -102,7 +103,7 @@ class Authetication:
 | 
			
		||||
        b64pwd = b64encode(SHA256.new(bytePass).digest())
 | 
			
		||||
        bcrypt_hash = bcrypt(b64pwd, 12)
 | 
			
		||||
 | 
			
		||||
        with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt') as json_file:
 | 
			
		||||
        with open(self.CONFIG_FILE_LOCATION) as json_file:
 | 
			
		||||
            data = json.load(json_file)
 | 
			
		||||
 | 
			
		||||
        if self.checkUserExists(username):
 | 
			
		||||
@@ -123,7 +124,7 @@ class Authetication:
 | 
			
		||||
 | 
			
		||||
                ##Save user data
 | 
			
		||||
                data['user'].append(user)
 | 
			
		||||
                with open(self.CONFIG_DIRECTORY_LOCATION + '\\config.txt', 'w') as outfile:
 | 
			
		||||
                with open(self.CONFIG_FILE_LOCATION, 'w') as outfile:
 | 
			
		||||
                    json.dump(data, outfile)
 | 
			
		||||
 | 
			
		||||
                auth_logger.debug("User saved!")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user