Masonite - TypeError: Can't convert 'Undefined' object to str implicitly

114 Views Asked by At

I'm using the Masonite framework and I'm getting an error when registering a user after running the craft auth command in Masonite 1.6. The end of the stack trace looks like:

{% for i, line in enumerate(open(stack.filename)) %}

TypeError: Can't convert 'Undefined' object to str implicitly

1

There are 1 best solutions below

0
On BEST ANSWER

This was fixed in Masonite 1.6.3. The problem was that there was a bug with passwords not being decoded back into a string after being hashed with bcrypt. Apparently MySQL converts bytes into a string before inserting into the database but Postgres and SQLite does not.

Upgrade

The fix is to upgrade Masonite by running:

pip install --upgrade -r requirements.txt

to upgrade to the latest version (so craft auth will not create a controller with this bug again)

Patch

and to patch the current application by changing ~line 20 in your RegisterController to:

password = bytes(bcrypt.hashpw(
    bytes(Request.input('password'), 'utf-8'), bcrypt.gensalt()
)).decode('utf-8')