annotate MoinMoin/support/passlib/handlers/digests.py @ 6096:86a41c2bedec

upgrade passlib from 1.6.2 to 1.6.5
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 05 Sep 2016 23:44:04 +0200
parents efd7c0be3339
children 7f0616feeae9
rev   line source
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 """passlib.handlers.digests - plain hash digests
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4 # imports
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 # core
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 import hashlib
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8 import logging; log = logging.getLogger(__name__)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 from warnings import warn
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10 # site
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 # pkg
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12 from passlib.utils import to_native_str, to_bytes, render_bytes, consteq
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 from passlib.utils.compat import bascii_to_str, bytes, unicode, str_to_uascii
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 import passlib.utils.handlers as uh
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15 from passlib.utils.md4 import md4
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 # local
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17 __all__ = [
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 "create_hex_hash",
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19 "hex_md4",
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 "hex_md5",
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21 "hex_sha1",
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 "hex_sha256",
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 "hex_sha512",
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24 ]
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26 #=============================================================================
6096
86a41c2bedec upgrade passlib from 1.6.2 to 1.6.5
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5919
diff changeset
27 # helpers for hexadecimal hashes
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29 class HexDigestHash(uh.StaticHandler):
6096
86a41c2bedec upgrade passlib from 1.6.2 to 1.6.5
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5919
diff changeset
30 """this provides a template for supporting passwords stored as plain hexadecimal hashes"""
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 #===================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 # class attrs
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 #===================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 _hash_func = None # hash function to use - filled in by create_hex_hash()
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35 checksum_size = None # filled in by create_hex_hash()
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 checksum_chars = uh.HEX_CHARS
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 #===================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 # methods
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40 #===================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 @classmethod
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 def _norm_hash(cls, hash):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 return hash.lower()
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 def _calc_checksum(self, secret):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 if isinstance(secret, unicode):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47 secret = secret.encode("utf-8")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 return str_to_uascii(self._hash_func(secret).hexdigest())
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50 #===================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51 # eoc
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 #===================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54 def create_hex_hash(hash, digest_name, module=__name__):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 # NOTE: could set digest_name=hash.name for cpython, but not for some other platforms.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 h = hash()
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 name = "hex_" + digest_name
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 return type(name, (HexDigestHash,), dict(
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59 name=name,
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
60 __module__=module, # so ABCMeta won't clobber it
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
61 _hash_func=staticmethod(hash), # sometimes it's a function, sometimes not. so wrap it.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
62 checksum_size=h.digest_size*2,
6096
86a41c2bedec upgrade passlib from 1.6.2 to 1.6.5
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5919
diff changeset
63 __doc__="""This class implements a plain hexadecimal %s hash, and follows the :ref:`password-hash-api`.
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
64
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
65 It supports no optional or contextual keywords.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
66 """ % (digest_name,)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
67 ))
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
68
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
69 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
70 # predefined handlers
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
71 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
72 hex_md4 = create_hex_hash(md4, "md4")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
73 hex_md5 = create_hex_hash(hashlib.md5, "md5")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
74 hex_md5.django_name = "unsalted_md5"
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
75 hex_sha1 = create_hex_hash(hashlib.sha1, "sha1")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
76 hex_sha256 = create_hex_hash(hashlib.sha256, "sha256")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
77 hex_sha512 = create_hex_hash(hashlib.sha512, "sha512")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
78
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
79 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
80 # htdigest
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
81 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
82 class htdigest(uh.PasswordHash):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
83 """htdigest hash function.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
84
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
85 .. todo::
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
86 document this hash
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
87 """
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
88 name = "htdigest"
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
89 setting_kwds = ()
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
90 context_kwds = ("user", "realm", "encoding")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
91 default_encoding = "utf-8"
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
92
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
93 @classmethod
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
94 def encrypt(cls, secret, user, realm, encoding=None):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
95 # NOTE: this was deliberately written so that raw bytes are passed through
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
96 # unchanged, the encoding kwd is only used to handle unicode values.
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
97 if not encoding:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
98 encoding = cls.default_encoding
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
99 uh.validate_secret(secret)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
100 if isinstance(secret, unicode):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
101 secret = secret.encode(encoding)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
102 user = to_bytes(user, encoding, "user")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
103 realm = to_bytes(realm, encoding, "realm")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
104 data = render_bytes("%s:%s:%s", user, realm, secret)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
105 return hashlib.md5(data).hexdigest()
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
106
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
107 @classmethod
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
108 def _norm_hash(cls, hash):
6096
86a41c2bedec upgrade passlib from 1.6.2 to 1.6.5
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents: 5919
diff changeset
109 """normalize hash to native string, and validate it"""
5919
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
110 hash = to_native_str(hash, param="hash")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
111 if len(hash) != 32:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
112 raise uh.exc.MalformedHashError(cls, "wrong size")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
113 for char in hash:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
114 if char not in uh.LC_HEX_CHARS:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
115 raise uh.exc.MalformedHashError(cls, "invalid chars in hash")
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
116 return hash
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
117
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
118 @classmethod
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
119 def verify(cls, secret, hash, user, realm, encoding="utf-8"):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
120 hash = cls._norm_hash(hash)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
121 other = cls.encrypt(secret, user, realm, encoding)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
122 return consteq(hash, other)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
123
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
124 @classmethod
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
125 def identify(cls, hash):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
126 try:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
127 cls._norm_hash(hash)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
128 except ValueError:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
129 return False
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
130 return True
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
131
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
132 @classmethod
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
133 def genconfig(cls):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
134 return None
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
135
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
136 @classmethod
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
137 def genhash(cls, secret, config, user, realm, encoding="utf-8"):
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
138 if config is not None:
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
139 cls._norm_hash(config)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
140 return cls.encrypt(secret, user, realm, encoding)
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
141
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
142 #=============================================================================
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
143 # eof
efd7c0be3339 added passlib 1.6.1 to MoinMoin/support/
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
144 #=============================================================================