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()