Create SSHA1 Password for OpenLDAP in Python
Aus Markus' Wiki
Version vom 20. März 2013, 14:03 Uhr von Markus (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „Composed based on this contribution: * http://www.openldap.org/faq/data/cache/347.html Seems to work: #!/usr/bin/python import hashlib import os from …“)
Composed based on this contribution:
Seems to work:
#!/usr/bin/python import hashlib import os from base64 import encodestring as encode from base64 import decodestring as decode def makeSecret(password): salt = os.urandom(4) h = hashlib.sha1(password) h.update(salt) return "{SSHA}" + encode(h.digest() + salt) def checkPassword(challenge_password, password): challenge_bytes = decode(challenge_password[6:]) digest = challenge_bytes[:20] salt = challenge_bytes[20:] hr = hashlib.sha1(password) hr.update(salt) return digest == hr.digest() pp = makeSecret("test123") print pp