由于某种原因,我没有使用默认User
模型进行身份验证。
对于密码检查,我为我的模型创建了与check_password
相同的方法,但它始终返回False
。
我的代码:
class MyModel(models.Model):
'''
useranme password fields comes here
'''
def check_password(password, encoded, setter=None, preferred='default'):
"""
Returns a boolean of whether the raw password matches the three
part encoded digest.
If setter is specified, it'll be called when you need to
regenerate the password.
"""
if password is None or not is_password_usable(encoded):
return False
preferred = get_hasher(preferred)
hasher = identify_hasher(encoded)
must_update = hasher.algorithm != preferred.algorithm
if not must_update:
must_update = preferred.must_update(encoded)
is_correct = hasher.verify(password, encoded)
if setter and is_correct and must_update:
setter(password)
return is_correct
当我使用Mymodel实例调用此方法时,它每次都返回False。
user = Mymodel.objects.get(username=username)
user.check_password(raw_password_entered_by_user)