Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Fix: Add Password Validation to Account Creation (#25382)

Newton José6574e9f0b2ac
diff --git a/api/services/account_service.py b/api/services/account_service.py
index f66c1aa6772..f9179593507 100644
--- a/api/services/account_service.py
+++ b/api/services/account_service.py
@@ -246,6 +246,8 @@ class AccountService:
account.name = name
if password:
+ valid_password(password)
+
# generate password salt
salt = secrets.token_bytes(16)
base64_salt = base64.b64encode(salt).decode()
diff --git a/api/tests/test_containers_integration_tests/services/test_account_service.py b/api/tests/test_containers_integration_tests/services/test_account_service.py
index 6b5ac713e6c..dac1fe643a2 100644
--- a/api/tests/test_containers_integration_tests/services/test_account_service.py
+++ b/api/tests/test_containers_integration_tests/services/test_account_service.py
@@ -91,6 +91,28 @@ class TestAccountService:
assert account.password is None
assert account.password_salt is None
+ def test_create_account_password_invalid_new_password(
+ self, db_session_with_containers, mock_external_service_dependencies
+ ):
+ """
+ Test account create with invalid new password format.
+ """
+ fake = Faker()
+ email = fake.email()
+ name = fake.name()
+ # Setup mocks
+ mock_external_service_dependencies["feature_service"].get_system_features.return_value.is_allow_register = True
+ mock_external_service_dependencies["billing_service"].is_email_in_freeze.return_value = False
+
+ # Test with too short password (assuming minimum length validation)
+ with pytest.raises(ValueError): # Password validation error
+ AccountService.create_account(
+ email=email,
+ name=name,
+ interface_language="en-US",
+ password="invalid_new_password",
+ )
+
def test_create_account_registration_disabled(self, db_session_with_containers, mock_external_service_dependencies):
"""
Test account creation when registration is disabled.