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: ensure generated password satisfies the password policy (#35672)

kurokobo73ecdd5494c0
diff --git a/api/commands/account.py b/api/commands/account.py
index 761323a73d0..0d99ce7a0fa 100644
--- a/api/commands/account.py
+++ b/api/commands/account.py
@@ -113,8 +113,18 @@ def create_tenant(email: str, language: str | None = None, name: str | None = No
# Validates name encoding for non-Latin characters.
name = name.strip().encode("utf-8").decode("utf-8") if name else None
- # generate random password
- new_password = secrets.token_urlsafe(16)
+ # Generate a random password that satisfies the password policy.
+ # The iteration limit guards against infinite loops caused by unexpected bugs in valid_password.
+ for _ in range(100):
+ new_password = secrets.token_urlsafe(16)
+ try:
+ valid_password(new_password)
+ break
+ except Exception:
+ continue
+ else:
+ click.echo(click.style("Failed to generate a valid password. Please try again.", fg="red"))
+ return
# register account
account = RegisterService.register(