passlib.hash.nthash - Windows' NT-HASH¶
Danger
This algorithm is dangerously insecure by modern standards. It is trivially broken, and should not be used if at all possible. For new code, see the list of recommended hashes.
This class implements the NT-HASH algorithm, used by Microsoft Windows NT
and successors to store user account passwords, supplanting
the much weaker lmhash algorithm.
This class can be used directly as follows:
from passlib.hash import nthash
# hash password
h = nthash.hash("password")
print(h)
# > '8846f7eaee8fb117ad06bdd830b7586c'
# verify password
print(nthash.verify("password", h))
# > True
print(nthash.verify("secret", h))
# > False
Tip
See the generic PasswordHash usage examples.
Interface¶
nthash
¶
nthash(checksum=None, use_defaults=False, **kwds)
This class implements the NT Password hash, and follows the :ref:password-hash-api.
It has no salt and a single fixed round.
The :meth:~passlib.ifc.PasswordHash.hash and :meth:~passlib.ifc.PasswordHash.genconfig methods accept no optional keywords.
Note that while this class outputs lower-case hexadecimal digests, it will accept upper-case digests as well.
encrypt
classmethod
¶
encrypt(*args, **kwds)
Legacy alias for :meth:hash.
.. deprecated:: 1.7
This method was renamed to :meth:!hash in version 1.7.
This alias will be removed in version 2.0, and should only
be used for compatibility with Passlib 1.3 - 1.6.
parsehash
classmethod
¶
parsehash(hash, checksum=True, sanitize=False)
[experimental method] parse hash into dictionary of settings.
this essentially acts as the inverse of :meth:hash: for most
cases, if hash = cls.hash(secret, **opts), then
cls.parsehash(hash) will return a dict matching the original options
(with the extra keyword checksum).
this method may not work correctly for all hashes, and may not be available on some few. its interface may change in future releases, if it's kept around at all.
Parameters:
-
hash–hash to parse
-
checksum–include checksum keyword? (defaults to True)
-
sanitize–mask data for sensitive fields? (defaults to False)
raw
classmethod
¶
raw(secret)
encode password using MD4-based NTHASH algorithm
Parameters:
-
secret–secret as unicode or utf-8 encoded bytes
Returns:
-
–
returns string of raw bytes
Format & Algorithm¶
A nthash consists of 32 hexadecimal digits, which encode the digest.
An example hash (of password) is 8846f7eaee8fb117ad06bdd830b7586c.
The digest is calculated by encoding the secret using UTF-16-LE,
taking the MD4 digest, and then encoding
that as hexadecimal.
FreeBSD Variant¶
For cross-compatibility, FreeBSD's crypt supports storing
NTHASH digests in a manner compatible with the modular-crypt-format,
to enable administrators to store user passwords in a manner compatible with
the SMB/CIFS protocol. This is accomplished by assigning NTHASH digests the
identifier $3$, and prepending the identifier to the normal (lowercase)
NTHASH digest. An example digest (of password) is
$3$$8846f7eaee8fb117ad06bdd830b7586c (note the doubled $$).
bsd_nthash¶
This object supports FreeBSD's representation of NTHASH
(which is compatible with the modular-crypt-format),
and follows the password-hash-api.
It has no salt and a single fixed round.
The hash() and genconfig() methods accept no optional keywords.
Warning
Changed in 1.6: This hash was named nthash under previous releases of Passlib.
Security Issues¶
This algorithm should be considered completely broken:
- It has no salt.
- The MD4 message digest has been severely compromised by collision and preimage attacks.
- Brute-force and pre-computed attacks exist targeting MD4 hashes in general, and the encoding used by NTHASH in particular.