Forums

having issue with "check_password_hash" from werkzeug.security

Here is an error:

File "/home/Julia/calculator/methods.py", line 104, in check_if_admin
    check = check_password_hash(find_password, password)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/security.py", line 124, in check_password_hash
    return safe_str_cmp(_hash_internal(method, salt, password), hashval)
File "/usr/local/lib/python2.7/dist-packages/werkzeug/security.py", line 48, in safe_str_cmp
    if len(a) != len(b):
TypeError: object of type 'NoneType' has no len()

and the strange thing that after I enter login data - log shows me this: 2014-06-02 19:06:54,784 :(u'admin', 1, 0). Password is a second value, but is not 1 for admin. By the way for all users it shows password as 1.

Has anyone met such issue with "check_password_hash"? I`ll really appreciate any help.

What happens if you log the values of find_password and password just before that call? It looks like one of them is None.

The problem is with the fact that I have admin record in database with already hashed password. When I insert admins password - "generate_password_hash" function produces the other hash. That is why password from database and inserted one don`t match. Its strange, on development server it works fine.

Well I found solution that works for me.

I deleted database from app dir. And since I have scripts which create and fill database there is no need of having database manually loaded. Now it works fine.

I suppose that "generate_password_hash" function produces different hash at local machine and being applied elsewhere.

Are you using a random 'salt'? If so, it seems to produce a different hash every time - see:

http://stackoverflow.com/questions/23432478/flask-generate-password-hash-not-constant-output