Django未通过用户身份验证

时间:2017-04-25 11:57:06

标签: python mysql django postgresql python-3.x

保存后检查用户密码失败

Django 1.11 postgres(postgis)

在settings.py

中定义的密码哈希值
PASSWORD_HASHERS = [
    'django.contrib.auth.hashers.PBKDF2PasswordHasher',
    'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
    'django.contrib.auth.hashers.Argon2PasswordHasher',
    'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
    'django.contrib.auth.hashers.BCryptPasswordHasher', ]

我想做什么:

> ./manage shell
    In [1]: from accounts.models import User

In [2]: u = User.objects.get(pk=1)

In [3]: u.password
Out[3]: 'pbkdf2_sha256$36000$LlYFKXzibqZP$t7njfFLddkUos0ePjMTlSqM2KVhduFVvXTEobiHbXng=                                                   '

In [4]: u.check_password('123456')
Out[4]: False

In [5]: u.refresh_from_db()

In [6]: u.set_password('123456')

In [7]: u.password
Out[7]: 'pbkdf2_sha256$36000$WwQpAA6KyVX8$2GMy23BV1go4h/f/nlBezA50Jsc7QOi2sBlZsYhPAYM='

In [8]: u.check_password('123456')
Out[8]: True

In [9]: u.refresh_from_db()

In [10]: u.password
Out[10]: 'pbkdf2_sha256$36000$LlYFKXzibqZP$t7njfFLddkUos0ePjMTlSqM2KVhduFVvXTEobiHbXng=                                                   '

In [11]: u.check_password('123456')
Out[11]: False

更新:首先我认为是因为将数据库从mysql迁移到postgres,但即使是重置密码

0 个答案:

没有答案