Skip to content

Instantly share code, notes, and snippets.

@alertedsnake
Last active August 29, 2015 14:19
Show Gist options
  • Save alertedsnake/bef343e7a5ccf4c8e3de to your computer and use it in GitHub Desktop.
Save alertedsnake/bef343e7a5ccf4c8e3de to your computer and use it in GitHub Desktop.
Generate OpenLDAP SSHA password
import getpass
import hashlib
import os
from base64 import urlsafe_b64encode as encode
def make_secret(password):
salt=os.urandom(4)
sha = hashlib.sha1(password)
sha.update(salt)
digest_salt_b64 = '{}{}'.format(sha.digest(), salt).encode('base64').strip()
return '{{SSHA}}{}'.format(digest_salt_b64)
if __name__ == '__main__':
print(make_secret(getpass.getpass("password: ")))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment