digests_4.py 604 B

123456789101112
  1. def hash(cls, secret, user, realm, encoding=None):
  2. # NOTE: this was deliberately written so that raw bytes are passed through
  3. # unchanged, the encoding kwd is only used to handle unicode values.
  4. if not encoding:
  5. encoding = cls.default_encoding
  6. uh.validate_secret(secret)
  7. if isinstance(secret, unicode):
  8. secret = secret.encode(encoding)
  9. user = to_bytes(user, encoding, "user")
  10. realm = to_bytes(realm, encoding, "realm")
  11. data = render_bytes("%s:%s:%s", user, realm, secret)
  12. return hashlib.md5(data).hexdigest()