Last active
October 1, 2015 06:08
-
-
Save wrunk/1934512 to your computer and use it in GitHub Desktop.
Quick python sha224 digest example
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
#!/usr/bin/env python | |
''' | |
Example of a way you could hash a password with a salt. | |
Pass the password as the first and only parameter. | |
WARNING this is just an example. NEVER put a real password in the clear | |
on the command line like this. | |
''' | |
import hashlib | |
import sys | |
SALT = '23klj23#$KJ#@kj234klj23#KJ429sglakjse' | |
def digest(password): | |
h = hashlib.sha224(password) | |
h.update(SALT) | |
return h.hexdigest() | |
def main(): | |
print digest(sys.argv[1]) | |
if __name__ == "__main__": | |
main() | |
# Additionally, heres a really simple example of getting the sha1 | |
# hash of an email addr. | |
# This will return a 40 character hexadecimal string. | |
def hash_email_addr(email_addr): | |
return hashlib.sha1(email_addr.lower().strip()).hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment