简体   繁体   English

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

[英]No hashing while trying to Hash using Python BCrypt

I have a view like: 我有这样的看法

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 
        })

RegistrationForm 报名表格

class RegistrationForm(ModelForm):
    userPass = forms.CharField(widget=forms.PasswordInput, label='Password')
    class Meta:
        model = Client
        fields = ['userNm','userPass']

Why is it storing in plaintext? 为什么以明文形式存储?

I'm trying to take the cleaned_data[] of userPass from a modelfrom and hash it prior to sending to the db. 我正在尝试从modelfrom中获取userPasscleaned_data[]并对其进行哈希处理,然后再发送到db。

Try bcrypt.hashpw(clearPass.encode("utf-8"), bcrypt.gensalt(14)) . 尝试bcrypt.hashpw(clearPass.encode("utf-8"), bcrypt.gensalt(14))

This is because your clearPass is by default an Unicode object and that it can't be directly used in your hashing function, the encode("utf-8") converts it into a standard string and then it can be hashed. 这是因为默认情况下,您的clearPass是Unicode对象,并且不能直接在哈希函数中使用,它的encode("utf-8")将其转换为标准字符串,然后可以对其进行哈希处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Python中使用Bcrypt哈希密码时出错 - Getting error while hashing password using Bcrypt in Python 使用python / bcrypt将密码保存为用户集合中mongodb中的salted哈希 - save password as salted hash in mongodb in users collection using python/bcrypt 使用 bcrypt 密码散列进行用户身份验证 - using bcrypt password hashing for user authentication 在 python 中使用 bcrypt 进行散列时,如何使用特定字符串作为我的 salt 并配置成本因子 - How do I use a specific string as my salt and configure the cost factor when hashing using bcrypt in python Django 并使用 bcrypt 到 hash 并检查登录密码 - Django and using bcrypt to hash and check login passwords 在登录 function 中使用 Python、ZF754876303939E78E6A5 - Getting a password to matches with its hash in a login function using Python, SQlite and bcrypt 尝试导入 pysftp 或 paramiko 时出现 bcrypt 错误 - bcrypt error while trying to import pysftp or paramiko 在Ubuntu 14.04中使用pip install bcrypt安装Python Bcrypt时出错 - Error Installing Python Bcrypt using pip install bcrypt in Ubuntu 14.04 Python hash_ring不均匀分布,什么是一致的哈希替代方案? - Python hash_ring not distributing uniformly, what are consistent hashing alternatives? Python MD5 散列相同的内容返回不同的散列 - Python MD5 hashing same content returns different hash
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM