diff --git a/monkey/monkey_island/cc/environment/user_creds.py b/monkey/monkey_island/cc/environment/user_creds.py index f1989a6a4..aba349f2d 100644 --- a/monkey/monkey_island/cc/environment/user_creds.py +++ b/monkey/monkey_island/cc/environment/user_creds.py @@ -2,8 +2,6 @@ from __future__ import annotations from typing import Dict -import bcrypt - from monkey_island.cc.resources.auth.auth_user import User @@ -25,9 +23,3 @@ class UserCreds: def to_auth_user(self) -> User: return User(1, self.username, self.password_hash) - - @classmethod - def from_cleartext(cls, username, cleartext_password): - password_hash = bcrypt.hashpw(cleartext_password.encode("utf-8"), bcrypt.gensalt()).decode() - - return cls(username, password_hash) diff --git a/monkey/monkey_island/cc/resources/auth/registration.py b/monkey/monkey_island/cc/resources/auth/registration.py index 8803a7d12..8c7ca5054 100644 --- a/monkey/monkey_island/cc/resources/auth/registration.py +++ b/monkey/monkey_island/cc/resources/auth/registration.py @@ -1,5 +1,6 @@ import json +import bcrypt import flask_restful from flask import make_response, request @@ -27,5 +28,6 @@ def _get_user_credentials_from_request(request): username = cred_dict.get("user", "") password = cred_dict.get("password", "") + password_hash = bcrypt.hashpw(password.encode("utf-8"), bcrypt.gensalt()).decode() - return UserCreds.from_cleartext(username, password) + return UserCreds(username, password_hash) diff --git a/monkey/tests/monkey_island/cc/environment/test_user_creds.py b/monkey/tests/monkey_island/cc/environment/test_user_creds.py index 60bb2afa2..802c13416 100644 --- a/monkey/tests/monkey_island/cc/environment/test_user_creds.py +++ b/monkey/tests/monkey_island/cc/environment/test_user_creds.py @@ -1,5 +1,3 @@ -import bcrypt - from monkey_island.cc.environment.user_creds import UserCreds TEST_USER = "Test" @@ -41,16 +39,7 @@ def test_to_auth_user_full_credentials(): assert auth_user.secret == TEST_HASH -def test_get_from_cleartext(monkeypatch): - monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT) - - creds = UserCreds.from_cleartext(TEST_USER, "Test_Password") - assert creds.password_hash == "$2b$12$JA7GdT1iyfIsquF2cTZv2.NdGFuYbX1WGfQAOyHlpEsgDTNGZ0TXG" - - def test_member_values(monkeypatch): - monkeypatch.setattr(bcrypt, "gensalt", lambda: TEST_SALT) - creds = UserCreds(TEST_USER, TEST_HASH) assert creds.username == TEST_USER assert creds.password_hash == TEST_HASH