目前我的應用程序在提交時正確地存儲密碼,但它沒有被散列並且以明文存儲。安全地存儲密碼哈希django
我的觀點:
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']
models.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
中似乎認爲它只是發送t他的價值是clearPassNoHash
,因爲它的價值是.cleaned_data[]
的一部分。任何想法我做錯了什麼?我希望得到一些幫助,正確實施這個以散列通行證。
謝謝
不幸的是,我想這一點 - 它提交的形式,但形式包含非散列,明文密碼。我也嘗試過:'userPassHashed = bcrypt.hashpw(RegForm.cleaned_data ['userPass']。encode(「utf-8」),bcrypt.gensalt(14))'但是這也行不通。有什麼想法嗎? – CodeTalk