如何生成符合Django中验证器的密码?

发布于 2025-02-03 07:01:14 字数 301 浏览 2 评论 0原文

我使用user.objects.make_random_password()来生成 new 用户的密码,但是我发现此方法正在创建不符合验证器的密码(auth_pass_pass_validators) )在Django中配置。

我还尝试了从django.contrib.auth.hashers导入Make_password,但是Hashed密码不符合所有密码验证标准,因为太长了。

我想知道是否有一个基于auth_password_validators创建密码的函数?

I used User.objects.make_random_password() to generate passwords for new users, however I found out that this method was creating passwords which didn't comply with the validators (AUTH_PASSWORD_VALIDATORS) that are configured in Django.

I also tried with from django.contrib.auth.hashers import make_password, but the hashed password does not match all the password validation criteria because is too long.

I want to know if there is a function which creates passwords based on AUTH_PASSWORD_VALIDATORS?.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

歌枕肩 2025-02-10 07:01:14

好吧,您应该尝试创建自己的密码创建者。

尝试此功能我为您创建新密码。

import random 
def create_new_password():
    alphas = "abcdefghijklmnopqrstuvwxyz"
    alphas_cap = alphas.upper()
    numbers = "12345678901234567890123456"
    special_chars = "!@#$%^&*()_+/!@#$%^&*()_+/"
    password_characters = [alphas , alphas_cap , numbers , special_chars ]
    new_password = ""
    for i in range(16) : 
        n = random.randint(0,3)
        chars_used = password_characters[n]
        char = chars_used[random.randint(0,25)]
        new_password += char
    return new_password
print(create_new_password())

Well, you should try to create your own password creator.

Try this function I made for you to create new passwords.

import random 
def create_new_password():
    alphas = "abcdefghijklmnopqrstuvwxyz"
    alphas_cap = alphas.upper()
    numbers = "12345678901234567890123456"
    special_chars = "!@#$%^&*()_+/!@#$%^&*()_+/"
    password_characters = [alphas , alphas_cap , numbers , special_chars ]
    new_password = ""
    for i in range(16) : 
        n = random.randint(0,3)
        chars_used = password_characters[n]
        char = chars_used[random.randint(0,25)]
        new_password += char
    return new_password
print(create_new_password())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文