Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

python - PASSWORD_HASHERS setting in Django

i have an error when ever i try to login by any User error

Unknown password hashing algorithm 'sahar'. Did you specify it in the PASSWORD_HASHERS setting?

Views.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)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It means there is a plain text 'sahar' stored as the password of the account of a user who tries to log in.
Update the password of the user in Admin or 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()

Also check your other views to correct the user.password = '...' and User.objects.create(password='...') usages.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...