Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PASSWORD_HASHERS setting in Django

Tags:

python

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)
like image 671
May Avatar asked Apr 20 '12 12:04

May


2 Answers

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.

like image 67
okm Avatar answered Oct 27 '22 00:10

okm


This is the best way to save log in details you can create an object from the form as

user = form.save(commit=False)

then clean the data to remove any scripts entered in the form fields.

username = form.cleaned_data['username']
password = form.cleaned_data['password']
user.set_password(password)
user.save()
like image 31
Alpha Nganga Avatar answered Oct 27 '22 00:10

Alpha Nganga