passlib
passlib copied to clipboard
'hash could not be identified' - need yescrypt support
linux (Ubuntu)use yescrypt hash algorithms: man 5 crypt
yescrypt
yescrypt is a scalable passphrase hashing scheme designed by Solar Designer, which is based on Colin Percival’s scrypt. Recommended for new
hashes.
Prefix
"$y$"
Hashed passphrase format
\$y\$[./A‐Za‐z0‐9]+\$[./A‐Za‐z0‐9]{,86}\$[./A‐Za‐z0‐9]{43}
for root user, get "hash could not be identified"
(venv) root@house:/tmp# cat /etc/shadow | grep root
root:$y$j9T$iEdl4odOxkTiR6QyO7KOg1$GYaeesPiNSCuRh7qGPbahNP5fhfP1OG1nfOG8JsRxX/:19802:0:99999:7:::
(venv) root@house:/tmp# cat ppp.py
import spwd, os
from passlib.hosts import host_context
hash = spwd.getspnam(os.environ['USER']).sp_pwd
print(host_context.verify("123456", hash))
(venv) root@house:/tmp#
(venv) root@house:/tmp# python ppp.py
/tmp/ppp.py:1: DeprecationWarning: 'spwd' is deprecated and slated for removal in Python 3.13
import spwd, os
Traceback (most recent call last):
File "/tmp/ppp.py", line 4, in <module>
print(host_context.verify("123456", hash))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/passlib/context.py", line 2343, in verify
record = self._get_or_identify_record(hash, scheme, category)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/passlib/context.py", line 2031, in _get_or_identify_record
return self._identify_record(hash, category)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/venv/lib/python3.11/site-packages/passlib/context.py", line 1132, in identify_record
raise exc.UnknownHashError("hash could not be identified")
passlib.exc.UnknownHashError: hash could not be identified