Skip to content

Instantly share code, notes, and snippets.

@ulif
Created May 11, 2016 11:25
Show Gist options
  • Save ulif/d86d0b3bf03492c340ffa202daa9264b to your computer and use it in GitHub Desktop.
Save ulif/d86d0b3bf03492c340ffa202daa9264b to your computer and use it in GitHub Desktop.
Turn hashed LDAP passwords into htpasswd-compatible ones.
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