dimanche 17 juillet 2016

Using .encode('utf-8') and still getting an Unicode-objects must be encoded before hashing error

When I have searched for the error, all the answers point to using .encode('utf-8'). I added that to my code and I am still getting the same error. Here is my code

def login(request):
    password=request.POST['password']
    email=request.POST['email']

    try:
        d2 = Register.objects.latest('created_at')
        registered = Register.objects.get(email = email)
    except:
        return HttpResponse(Register.userManager.not_found_email())

    pw_bytes = password.encode('utf-8')
    hashed = bcrypt.hashpw(pw_bytes, registered.salt)
    print hashed

    if hashed:
        print hashed
        print registered.password
        return HttpResponse(Register.userManager.incorrect_password())

    return render(request, 'validation_app/success.html')

registered.salt is bcrypt.gensalt() saved to my db

Aucun commentaire:

Enregistrer un commentaire