如何为bcrypt.hashpw设置盐? [英] How can I set salt for bcrypt.hashpw?

查看:1114
本文介绍了如何为bcrypt.hashpw设置盐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


密码= bcrypt.hashpw(密码,盐)
repeatpassword = bcrypt.hashpw(重复密码,盐)

我的错误是第二行。

  ValueError at / register 

无效的盐

请求方法:POST
请求URL:http://127.0.0.1:8000/register
Django版本:1.3.1
异常类型:ValueError
异常值:

无效salt

异常位置:/ home / user1 /djangoblog/blog/views.py注册,行70
Python可执行文件:/ usr / bin / python
Python版本:2.6.6
Python路径:

['/ home / user1 / djangoblog',
'/usr/lib/python2.6',
'/usr/lib/python2.6/plat-linux2',
' /usr/lib/python2.6/lib-tk',
'/usr/lib/python2.6/lib-old',
'/usr/lib/python2.6/lib-dynload ',
'/usr/local/lib/python2.6/dist-packages',
'/ usr / l ib / python2.6 / dist-packages',
'/usr/lib/python2.6/dist-packages/gst-0.10',
'/usr/lib/pymodules/python2.6' ,
'/usr/lib/pymodules/python2.6/gtk-2.0']

做什么?
我需要每次设置一些默认的盐值而不是随机盐。

解决方案

我认为,在项目页面中找到的示例,您需要这样:

  salt = bcrypt.gensalt()
password = bcrypt.hashpw(密码,盐)
repeatpassword = bcrypt.hashpw (repeatpassword,salt)


    salt = 'yhnqazolr123098765'
    password = bcrypt.hashpw(password,salt)
    repeatpassword = bcrypt.hashpw(repeatpassword,salt)

I got error for the second line.

ValueError at /register

Invalid salt

Request Method:     POST
Request URL:    http://127.0.0.1:8000/register
Django Version:     1.3.1
Exception Type:     ValueError
Exception Value:    

Invalid salt

Exception Location:     /home/user1/djangoblog/blog/views.py in register, line 70
Python Executable:  /usr/bin/python
Python Version:     2.6.6
Python Path:    

['/home/user1/djangoblog',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/usr/lib/python2.6/lib-old',
 '/usr/lib/python2.6/lib-dynload',
 '/usr/local/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages/gst-0.10',
 '/usr/lib/pymodules/python2.6',
 '/usr/lib/pymodules/python2.6/gtk-2.0']

What to do? I need to set some default salt value rather than random salt every time.

解决方案

I think that, as in the example found in the project page, you need something like this:

salt = bcrypt.gensalt()
password = bcrypt.hashpw(password, salt)
repeatpassword = bcrypt.hashpw(repeatpassword,salt)

这篇关于如何为bcrypt.hashpw设置盐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆