Island: Rename and relocate methods in AuthenticationService

This commit is contained in:
Mike Salvatore 2021-10-08 12:10:28 -04:00
parent 8a2bae7e14
commit 1be7232983
1 changed files with 14 additions and 14 deletions

View File

@ -28,30 +28,26 @@ class AuthenticationService:
def register_new_user(cls, username: str, password: str): def register_new_user(cls, username: str, password: str):
credentials = UserCreds(username, _hash_password(password)) credentials = UserCreds(username, _hash_password(password))
env_singleton.env.try_add_user(credentials) env_singleton.env.try_add_user(credentials)
AuthenticationService.reset_datastore_encryptor(username, password) cls._reset_datastore_encryptor(username, password)
reset_database() reset_database()
@classmethod @classmethod
def authenticate(cls, username: str, password: str) -> bool: def authenticate(cls, username: str, password: str) -> bool:
if _credentials_match_registered_user(username, password): if _credentials_match_registered_user(username, password):
AuthenticationService.unlock_datastore_encryptor(username, password) cls._unlock_datastore_encryptor(username, password)
return True return True
return False return False
@staticmethod @classmethod
def unlock_datastore_encryptor(username: str, password: str): def _unlock_datastore_encryptor(cls, username: str, password: str):
secret = AuthenticationService._get_secret_from_credentials(username, password) secret = _get_secret_from_credentials(username, password)
unlock_datastore_encryptor(AuthenticationService.KEY_FILE_DIRECTORY, secret) unlock_datastore_encryptor(cls.KEY_FILE_DIRECTORY, secret)
@staticmethod @classmethod
def reset_datastore_encryptor(username: str, password: str): def _reset_datastore_encryptor(cls, username: str, password: str):
secret = AuthenticationService._get_secret_from_credentials(username, password) secret = _get_secret_from_credentials(username, password)
reset_datastore_encryptor(AuthenticationService.KEY_FILE_DIRECTORY, secret) reset_datastore_encryptor(cls.KEY_FILE_DIRECTORY, secret)
@staticmethod
def _get_secret_from_credentials(username: str, password: str) -> str:
return f"{username}:{password}"
def _hash_password(plaintext_password): def _hash_password(plaintext_password):
@ -70,3 +66,7 @@ def _credentials_match_registered_user(username: str, password: str) -> bool:
return (registered_user.username == username) and password_matches_hash( return (registered_user.username == username) and password_matches_hash(
password, registered_user.password_hash password, registered_user.password_hash
) )
def _get_secret_from_credentials(username: str, password: str) -> str:
return f"{username}:{password}"