11

当我尝试通过任何用户错误登录时出现错误

未知密码散列算法“sahar”。您是否在 PASSWORD_HASHERS 设置中指定了它?

视图.Py

def Login(request):
    state = "Please log in below..."
    username = password = ''
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        if user is not None:
                if user.is_active:
                    login(request, user)
                    return HttpResponseRedirect('/profile/')
                else:
                    return render_to_response('auth.html',RequestContext(request))

        else:
                return render_to_response('auth.html',RequestContext(request))
    else:
            return render_to_response('auth.html',RequestContext(request)
4

2 回答 2

25

这意味着有一个纯文本'sahar'存储为尝试登录的用户的帐户
密码。在 Admin 或 in 中更新用户的密码manage.py shell

user = User.objects.get(username=username)

# use set_password method
user.set_password('sahar')
user.save()

# INSTEAD OF 
user.password = 'sahar'
user.save()

还要检查您的其他视图以更正user.password = '...'User.objects.create(password='...')用法。

于 2012-04-20T13:11:57.570 回答
1

这是保存登录详细信息的最佳方式,您可以从表单创建对象

user = form.save(commit=False)

然后清理数据以删除在表单字段中输入的任何脚本。

username = form.cleaned_data['username']
password = form.cleaned_data['password']
user.set_password(password)
user.save()
于 2017-12-19T06:40:13.590 回答