def _search(self): if Users.user_exists(self.content['username']): self.response['key'] = Encryptor.get_public_key_as_string( Users.get_public_key(self.content['username'])) self.response['username'] = self.content['username'] else: self.status = ResponseCreator.status_codes['USER_DO_NOT_EXIST']
def test_user_exists(self): ''' test if a user exists or not ''' self.new_user.add_user() test_user = Users("Moringa", "1234") test_user.add_user() user_exists = Users.user_exists("Moringa","1234") self.assertTrue(user_exists)
def _delete_account(self): username = self.content['username'] if not Users.user_exists(username): self.status = ResponseCreator.status_codes['USER_DO_NOT_EXIST'] return user = Users.get_user(username) password = Encryptor.asymmetric_decrypt_message( key=ServerSession.get_private_key(), message=self.content['password']) if user.check_password(password): Users.delete_user_account(username)
def _register(self): username = self.content['username'] if Users.user_exists(username): self.status = ResponseCreator.status_codes['LOGIN_NOT_AVAILABLE'] return password = self.content['password'] public_key = self.content['public_key'] email = self.content['email'] usr = User(username=username, password=Encryptor.hash_message(password.encode()).decode(), email=email) Users.add_user(usr) UsersToPublicKeys.add_user_public_key(username, public_key)
def _authenticate(self): username = self.content['username'] if not Users.user_exists(username): self.status = ResponseCreator.status_codes['USER_DO_NOT_EXIST'] return user = Users.get_user(username) password = Encryptor.asymmetric_decrypt_message( key=ServerSession.get_private_key(), message=self.content['password']) if user.check_password(password): key = Encryptor.generate_symmetric_key() ServerSession.add_client_session_key(user.get_username(), key) pub_k = UsersToPublicKeys.get_public_key(username) print(username, ' session key ', key) encrypted_key = Encryptor.asymmetric_encrypt_message(key=pub_k, message=key) self.response = {'key': encrypted_key} else: self.status = ResponseCreator.status_codes['WRONG_PASSWORD']
def find_existing_user(username, login_password): ''' Function that authenticates users ''' return Users.user_exists(username, login_password)
def check_existing_user(username, login_password): ''' Function to authenticate user ''' return Users.user_exists(username, login_password)