目前,我的应用程序在提交时正确存储了密码,但它没有经过哈希处理,而是以明文形式存储。
我的观点:
def Registration(request):
RegForm = RegistrationForm(request.POST or None)
if request.method == 'POST':
if RegForm.is_valid():
clearUserName = RegForm.cleaned_data['userNm']
clearPassNoHash = RegForm.cleaned_data['userPass']
clearPass = bcrypt.hashpw(clearPassNoHash.encode("utf-8"), bcrypt.gensalt(14) )
RegForm.save()
try:
return HttpResponseRedirect('/Newuser/?userNm=' + clearUserName)
except:
raise ValidationError(('Invalid request'), code='300')
else:
RegForm = RegistrationForm()
return render(request, 'VA/reuse/register.html', {
'RegForm': RegForm
})
形式
class RegistrationForm(ModelForm):
userPass = forms.CharField(widget=forms.PasswordInput, label='Password')
class Meta:
model = Client
fields = ['userNm','userPass']
模型.py
class Client(models.Model):
userNm = models.EmailField(verbose_name="Email",max_length=50,unique=True) #userNm = <user's email>
userPass = models.CharField(verbose_name="Password", max_length=50)
问题在于clearPass
它似乎只是在发送值,clearPassNoHash
因为它的值是.cleaned_data[]
. 知道我做错了什么吗?对于正确实施此操作以散列通行证,我将不胜感激。
谢谢