Question

    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.

Was it helpful?

Solution

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)

OTHER TIPS

The format for salt is:

$Version$log2(NumRounds)$salt

where:

  • Version is 2,
  • 0 <= log2(NumRounds) < 32,
  • salt is a 22-byte base-64 encoded string.

I suggest you use bcrypt.gensalt() instead. There's no good reason for you to provide your own salt.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top