I am creating a django app and have run in to a problem with the login portion of it. Everything seems to be working fine but when I login in with the stored information I receive the ValueError with invalid salt. I've looked on here for solutions but nothing seems to be doing the trick. I tried using the encode('utf-8) solution but that doesn't work either.
def register(request):
check = User.objects.validateUser(request.POST)
if request.method != 'POST':
return redirect('/')
if check[0] == False:
for error in check[1]:
messages.add_message(request, messages.INFO, error, extra_tags="registration")
return redirect('/')
if check[0] == True:
hashed_pw = bcrypt.hashpw(request.POST.get('password').encode(), bcrypt.gensalt())
#create user
user = User.objects.create(
name = request.POST.get('name'),
email = request.POST.get('email'),
password = hashed_pw,
)
request.session['user_id'] = user.id
#route to quotes page
return redirect('/quotes')
def login(request):
if request.method != 'POST':
return redirect('/')
user = User.objects.filter(email = request.POST.get('email')).first()
if user and bcrypt.checkpw(request.POST.get('password').encode(), user.password.encode()):
request.session['user_id'] = user.id
return redirect('/quotes')
else:
messages.add_message(request, messages.INFO, 'invalid credentials', extra_tags="login")
return redirect('/')
return redirect('/quotes')
The issue seems to stem around the if user and bcrypt.checkpw() but I don't know what to do different?