dataset/seed/applicationservice/2022.03.08/openldap/funcs/ldap.py

13 lines
402 B
Python
Raw Normal View History

2022-03-08 19:42:28 +01:00
from os import urandom as _urandom
from hashlib import sha1 as _sha1
from base64 import encodebytes as _encodebytes, b64encode as _b64encode
# unproudly borrowed from
# http://www.openldap.org/faq/data/cache/347.html
def ssha_encode(password):
salt = _urandom(4)
h = _sha1(password.encode())
h.update(salt)
return _b64encode(b"{SSHA}" + _encodebytes(h.digest() + salt)[:-1]).decode()