Created
July 7, 2020 12:51
-
-
Save memoryleak/63ffaab008dfc4225b27f34bfb12f83e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
_HASH_RE = re.compile(r'[^a-zA-Z0-9./=]') | |
fields = "$6$7XhBc13.5MtmI1MQ$l4hdVQnszutOZxKYU/Ih5i9w9eFAIwMK4Nu9nDLrSTaD.p6eHhMgD.2C2s/PZhqTdqv8mk1/MDhHyWSW/HFly0".split("$") | |
maybe_invalid = False | |
if len(fields) >= 3: | |
# contains character outside the crypto constraint | |
if bool(_HASH_RE.search(fields[-1])): | |
maybe_invalid = True | |
# md5 | |
if fields[1] == '1' and len(fields[-1]) != 22: | |
maybe_invalid = True | |
# sha256 | |
if fields[1] == '5' and len(fields[-1]) != 43: | |
maybe_invalid = True | |
# sha512 | |
if fields[1] == '6' and len(fields[-1]) != 86: | |
maybe_invalid = True | |
else: | |
maybe_invalid = True | |
if maybe_invalid: | |
print("The input password appears not to have been hashed. " | |
"The 'password' argument must be encrypted for this module to work properly.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment