Skip to content

Instantly share code, notes, and snippets.

@wrunk
Last active October 1, 2015 06:08
Show Gist options
  • Save wrunk/1934512 to your computer and use it in GitHub Desktop.
Save wrunk/1934512 to your computer and use it in GitHub Desktop.
Quick python sha224 digest example
#!/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