Answer the question
In order to leave comments, you need to log in
Why might Django authenticate fail to hash the password?
Hello. There was a problem with the user authorization system in Django. Everything worked, but now for some reason the authenticate and login functions do not hash the password received from the form.
View for authorization:
def user_login(request):
if request.method == "POST":
form = Login(request.POST)
if form.is_valid():
form_clean = form.cleaned_data
user_login = form_clean['login']
user_password = form_clean['password']
print(user_password)
user = authenticate(username=user_login, password=user_password)
if user is not None:
login(request, user)
success_text = "Вы успешно вошли в систему."
return render(request, 'login.html', context={'success':success_text})
else:
form = Login()
err_message = 'Неправильная пара логин/пароль'
return render(request, 'login.html', context={'login':form, 'err':err_message})
else:
form = Login()
return render(request, 'login.html', context={'login':form})
def registrate(request):
if request.method == "POST":
registr_user = Registr(request.POST)
if registr_user.is_valid():
user = registr_user.save(commit=False)
user.set_password(registr_user.cleaned_data['password'])
user.save()
login(request, user)
return HttpResponseRedirect(reverse('main'))
else:
registr_user = Registr()
return render(request, 'registration.html', context={'form':registr_user})
else:
registr_user = Registr()
return render(request, 'registration.html', context={'form':registr_user})
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
MyUser.objects.create(user=instance, id=instance.id)
@receiver(post_save, sender=MyUser)
def change_user_data(sender, instance, **kwargs):
user = User.objects.get(id = instance.id)
user.set_password(instance.password)
user.save()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question