dify - ✅(Solved) Fix With low probability, the generated password does not meet the password requirements [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langgenius/dify#35671Fetched 2026-04-30 06:45:50
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
1
Author
Timeline (top)
closed ×1commented ×1cross-referenced ×1labeled ×1

Error Message

However, there is about a 3% chance that the generated string does not contain any digits, which results in an error during account registration because it does not meet the password requirements.

Root Cause

However, there is about a 3% chance that the generated string does not contain any digits, which results in an error during account registration because it does not meet the password requirements.

Fix Action

Fixed

PR fix notes

PR #35672: fix: ensure generated password satisfies the password policy

Description (problem / solution / changelog)

Summary

This PR includes following changes for create-tenant command:

  • Added a retry loop to keep generating a new password until it passes valid_password
  • Set an iteration limit of 100 to guard against infinite loops caused by unexpected bugs in valid_password
  • If the limit is reached, an error message is displayed and the command exits gracefully

Existing similar logic (for tests): https://github.com/langgenius/dify/blob/main/api/tests/test_containers_integration_tests/helpers/__init__.py

Closes #35671

Screenshots

BeforeAfter
......

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and cd web && pnpm exec vp staged (frontend) to appease the lint gods

Changed files

  • api/commands/account.py (modified, +12/-2)
RAW_BUFFERClick to expand / collapse

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.13.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Invoke create_tenant command.

✔️ Expected Behavior

Tenant is created without any errors.

❌ Actual Behavior

With low probability, the generated password does not meet the password requirements, which causes the failure.

In the create_tenant command, a password is generated using secrets.token_urlsafe(16).

https://github.com/langgenius/dify/blob/6fafeec41502152ec3552d1851aaeb3c22db1f02/api/commands/account.py#L116-L117

However, there is about a 3% chance that the generated string does not contain any digits, which results in an error during account registration because it does not meet the password requirements.

extent analysis

TL;DR

The issue can be fixed by modifying the password generation to ensure it meets the password requirements, possibly by using a more robust password generation method.

Guidance

  • Review the password requirements and consider using a library or function that generates passwords meeting specific criteria, such as containing at least one digit.
  • Verify the issue by checking the password generation code and testing it with multiple runs to confirm the 3% failure rate.
  • Consider adding a check after password generation to ensure it meets the requirements, and if not, regenerate the password.
  • Look into using a more reliable method than secrets.token_urlsafe(16) for generating passwords, such as using a combination of character sets (e.g., letters, digits, special characters).

Example

import secrets
import string

def generate_password(length=16):
    characters = string.ascii_letters + string.digits + string.punctuation
    while True:
        password = ''.join(secrets.choice(characters) for _ in range(length))
        if (any(c.islower() for c in password)
                and any(c.isupper() for c in password)
                and any(c.isdigit() for c in password)):
            return password

Notes

The current implementation relies on secrets.token_urlsafe(16), which may not guarantee the generation of a password meeting the specific requirements. The proposed solution aims to increase the reliability of password generation.

Recommendation

Apply workaround: Modify the password generation to use a more robust method, such as the example provided, to ensure generated passwords meet the requirements. This approach addresses the issue without relying on an upgrade to a fixed version, as the problem seems to stem from the password generation method rather than a version-specific bug.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

dify - ✅(Solved) Fix With low probability, the generated password does not meet the password requirements [1 pull requests, 1 comments, 2 participants]