Skip to content

Instantly share code, notes, and snippets.

@bsiegfreid
Created July 11, 2017 20:56
Show Gist options
  • Save bsiegfreid/2a028bc71bdf34bdcb904fe88264ea09 to your computer and use it in GitHub Desktop.
Save bsiegfreid/2a028bc71bdf34bdcb904fe88264ea09 to your computer and use it in GitHub Desktop.
Example of hashing a password.
import hashlib
import binascii
import os
import sys
# salt should be generated once per user
# if python 3.6 use salt = secrets.token_bytes(8)
salt = os.urandom(8)
# convert user provided password to bytes
password = bytes(sys.argv[1], 'utf-8')
dk = hashlib.pbkdf2_hmac('sha512', # algorithm name
password, # must be binary
salt, # 64 bit salt
10000 # Minimum 10,000 iterations per NIST Aug 2016
)
# convert to hexidecimal
hexed = binascii.hexlify(dk)
print(hexed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment