Skip to content

Instantly share code, notes, and snippets.

@thomseddon
Created February 21, 2018 13:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomseddon/1479603cac5b70ceaa5f9397f850eaf3 to your computer and use it in GitHub Desktop.
Save thomseddon/1479603cac5b70ceaa5f9397f850eaf3 to your computer and use it in GitHub Desktop.
crypt mksalt for python 2
import string as _string
from random import SystemRandom as _SystemRandom
_saltchars = _string.ascii_letters + _string.digits + './'
_sr = _SystemRandom()
# SHA512 mksalt extracted from https://github.com/python/cpython/blob/master/Lib/crypt.py
def mksalt():
return '$6$' + ''.join(_sr.choice(_saltchars) for char in range(16))
import mksalt
print(crypt.crypt('secret', mksalt.mksalt()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment