Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
尝试使用Python BCrypt进行哈希时不进行哈希_Python_Django_Hash_Bcrypt - Fatal编程技术网

尝试使用Python BCrypt进行哈希时不进行哈希

尝试使用Python BCrypt进行哈希时不进行哈希,python,django,hash,bcrypt,Python,Django,Hash,Bcrypt,我有一个观点像: def Registration(request): RegForm = RegistrationForm(request.POST or None) if request.method == 'POST': if RegForm.is_valid(): clearUserName = RegForm.cleaned_data['userNm'] clearPass = RegForm.cle

我有一个观点像:

def Registration(request):
    RegForm = RegistrationForm(request.POST or None)
    if request.method == 'POST':
        if RegForm.is_valid():
            clearUserName = RegForm.cleaned_data['userNm']   
            clearPass = RegForm.cleaned_data['userPass']

            hashedpasswithsalt = bcrypt.hashpw(clearPass, bcrypt.gensalt(14))

            RegForm.save()
            try:
                return HttpResponseRedirect('/Newuser/?userNm=' + clearUserName)
            except:
                raise ValidationError(('Invalid request'), code='300')    ## [ TODO ]: add a custom error page here.
    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']
为什么它存储在纯文本中

我正试图从modelfrom中获取
userPass
cleaned_data[]
,并在发送到db之前对其进行散列。

尝试
bcrypt.hashpw(clearPass.encode(“utf-8”),bcrypt.gensalt(14))


这是因为您的clearPass在默认情况下是一个Unicode对象,并且不能直接在哈希函数中使用,
encode(“utf-8”)
将其转换为标准字符串,然后可以对其进行哈希处理。

Try:from django.utils import force\u Unicode clearPass=force\u Unicode(RegForm.cleaned\u data['userPass'))这似乎有效,但密码仍然以明文形式存储。有什么原因吗?是的,我确信它们仍然以明文形式存储。我认为这是因为hashedpasswithsalt没有分配给RegForm.cleaned_data['userPass']”不幸的是,它仍然以明文形式存储。