Skip to content

Instantly share code, notes, and snippets.

@superboum
Created May 6, 2019 11:57
Show Gist options
  • Save superboum/e0c6c460172412f725da9f29944766e6 to your computer and use it in GitHub Desktop.
Save superboum/e0c6c460172412f725da9f29944766e6 to your computer and use it in GitHub Desktop.
Generate a valid LDAP SSHA
#!/usr/bin/python3
import getpass, sys, hashlib, os, base64
def makeSecret(password):
password = str(password).encode('utf-8')
salt = os.urandom(4)
h = hashlib.sha1(password)
h.update(salt)
return "{ssha}" + (base64.b64encode(h.digest() + salt)).decode('utf-8')
def askPassword():
pwd1 = getpass.getpass()
pwd2 = getpass.getpass("Again:")
if pwd1 != pwd2:
print("Password mismatch")
sys.exit(1)
return makeSecret(pwd1)
if __name__ == '__main__':
print(askPassword())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment