Errors handling crypt.crypt returning byte array instead of string

Issue #113 resolved
PatTheMav created an issue

The safe_crypt() method defined in utils/__init__.py (https://bitbucket.org/ecollins/passlib/src/f16891c4a7cb50cca16ccbce29a342bd0f0d2ad5/passlib/utils/__init__.py#lines-791) expects the result of crypt() to be a string, however I’ve found that on some systems (and more recent Python3/PyPy3 versions) it will be a byte array.

Thus the check for invalid prefixes fails as result[0] will receive an int not a str.

Placing the following two lines before the check fixes the issue:

if isinstance(result, bytes):
    result = result.decode('utf-8')

I haven’t been able to find out exactly why this output has changed, but I found that crypt.crypt returns byte arrays in all Py3 versions on my server (running Debian 10.2)

Comments (2)

  1. Log in to comment