maxcountryman / flask-bcrypt

Flask-Bcrypt is a Flask extension that provides bcrypt hashing utilities for your application.

Home Page:http://readthedocs.org/docs/flask-bcrypt/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Unicode-objects must be encoded before hashing

ser opened this issue · comments

password = b'super secret password'
hashpw= b'$2b$12$iyUDXZ.BX0jV2xfdZI7Ame4BB1lkIrZILNPe3Nax4gUMnqWU9lAv2'

  File "/home/ser/GIT/topitup/login_bp.py", line 82, in index
    if username and bcrypt_flask.check_password_hash(pwhash, password):
  File "/usr/lib/python3.4/site-packages/flask_bcrypt.py", line 180, in check_password_hash
    return safe_str_cmp(bcrypt.hashpw(password, pw_hash), pw_hash)
  File "/usr/lib/python3.4/site-packages/bcrypt/__init__.py", line 139, in hashpw
    raise TypeError("Unicode-objects must be encoded before hashing")
TypeError: Unicode-objects must be encoded before hashing

Python 3.4.3 (default, Mar 25 2015, 17:13:50)

Looks like you need to encode the password before hashing.

It's encoded. Clean python bcrypt module handles it without any issue.

Unfortunately I don't use Python 3 at all, so I can't really provide much help directly. Feel free to investigate and I'll gladly merge any appropriate fixes you might have.

My investigation made clear that flask-bcrypt is useless and makes things much more complicated and code longer and less clear. I would suggest removal of this extension.

I don't see how comments like that are helpful or constructive to anyone.