Created
May 11, 2016 11:25
-
-
Save ulif/d86d0b3bf03492c340ffa202daa9264b to your computer and use it in GitHub Desktop.
Turn hashed LDAP passwords into htpasswd-compatible ones.
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
def ldif2htaccess(ldif_hashed): | |
"""Turn LDIF hashed password into htpasswd compatible hash. | |
""" | |
pw = ldif_hashed.decode("base64") | |
if pw.startswith("{crypt}$1$"): | |
# this is in fact md5, non-apache mode | |
return pw[7:] | |
elif pw.lower().startswith("{crypt}"): | |
# old crypt(), really inscure | |
return pw[7:] | |
elif pw.lower().startswith("{md5}") and pw.endswith("=="): | |
# an md5 without salt, really insecure as well | |
return "$1$$%s" % pw[5:-3] | |
return pw | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment