How to check whether the sha-512 hash is valid? Wrote the following code
def is_pwd(passwd):
result = re.findall(r'[a-f0-9]{128}', passwd)
if result:
print "Valid"
else:
print "NOT a Valid"
But when I pass the hash: 3c9909afec25354d551dae21590bb26e38d53f2173b8d3dc3eee4c047e7ab1c1eb8b85103e3be7ba613b31bb5c9c36214dc9f14a42fd7a2fdb84856bca5c44c2''''!@#
Return - VALID
Thx.
If you definitely want to use regex, you should use re.match instead:
def is_pwd(passwd):
result = None
try: result = re.match(r'^\w{128}$', passwd).group(0)
except: pass
return result is not None
This method returns True for a valid password and False for an invalid one.
^ - Checks from the start of the string\w{128} - Checks for exactly 128 occurrences of an alphanumeric character$ - Confirms the end of the string (i.e. if you had more than 128 alphanums, it would return False)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With