Skip to content

Instantly share code, notes, and snippets.

@gnrfan
Created June 9, 2012 15:07
Show Gist options
  • Select an option

  • Save gnrfan/2901355 to your computer and use it in GitHub Desktop.

Select an option

Save gnrfan/2901355 to your computer and use it in GitHub Desktop.
Generate salt for use when hashing passwords
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