Created
May 6, 2019 11:57
-
-
Save superboum/e0c6c460172412f725da9f29944766e6 to your computer and use it in GitHub Desktop.
Generate a valid LDAP SSHA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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