Created
June 9, 2012 15:07
-
-
Save gnrfan/2901355 to your computer and use it in GitHub Desktop.
Generate salt for use when hashing passwords
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
| from os import urandom | |
| from base64 import b64encode | |
| DEFAULT_SALT_LENGTH = 12 | |
| def generate_salt(length=DEFAULT_SALT_LENGTH): | |
| salt = b64encode(urandom(length)) | |
| return salt | |
| if __name__ == '__main__': | |
| print "Salt of length %d: %s" % ( | |
| DEFAULT_SALT_LENGTH, | |
| generate_salt(DEFAULT_SALT_LENGTH) | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment