hashers.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. import base64
  2. import binascii
  3. import functools
  4. import hashlib
  5. import importlib
  6. import math
  7. import warnings
  8. from django.conf import settings
  9. from django.core.exceptions import ImproperlyConfigured
  10. from django.core.signals import setting_changed
  11. from django.dispatch import receiver
  12. from django.utils.crypto import (
  13. RANDOM_STRING_CHARS,
  14. constant_time_compare,
  15. get_random_string,
  16. pbkdf2,
  17. )
  18. from django.utils.module_loading import import_string
  19. from django.utils.translation import gettext_noop as _
  20. UNUSABLE_PASSWORD_PREFIX = "!" # This will never be a valid encoded hash
  21. UNUSABLE_PASSWORD_SUFFIX_LENGTH = (
  22. 40 # number of random chars to add after UNUSABLE_PASSWORD_PREFIX
  23. )
  24. def is_password_usable(encoded):
  25. """
  26. Return True if this password wasn't generated by
  27. User.set_unusable_password(), i.e. make_password(None).
  28. """
  29. return encoded is None or not encoded.startswith(UNUSABLE_PASSWORD_PREFIX)
  30. def verify_password(password, encoded, preferred="default"):
  31. """
  32. Return two booleans. The first is whether the raw password matches the
  33. three part encoded digest, and the second whether to regenerate the
  34. password.
  35. """
  36. fake_runtime = password is None or not is_password_usable(encoded)
  37. preferred = get_hasher(preferred)
  38. try:
  39. hasher = identify_hasher(encoded)
  40. except ValueError:
  41. # encoded is gibberish or uses a hasher that's no longer installed.
  42. fake_runtime = True
  43. if fake_runtime:
  44. # Run the default password hasher once to reduce the timing difference
  45. # between an existing user with an unusable password and a nonexistent
  46. # user or missing hasher (similar to #20760).
  47. make_password(get_random_string(UNUSABLE_PASSWORD_SUFFIX_LENGTH))
  48. return False, False
  49. hasher_changed = hasher.algorithm != preferred.algorithm
  50. must_update = hasher_changed or preferred.must_update(encoded)
  51. is_correct = hasher.verify(password, encoded)
  52. # If the hasher didn't change (we don't protect against enumeration if it
  53. # does) and the password should get updated, try to close the timing gap
  54. # between the work factor of the current encoded password and the default
  55. # work factor.
  56. if not is_correct and not hasher_changed and must_update:
  57. hasher.harden_runtime(password, encoded)
  58. return is_correct, must_update
  59. def check_password(password, encoded, setter=None, preferred="default"):
  60. """
  61. Return a boolean of whether the raw password matches the three part encoded
  62. digest.
  63. If setter is specified, it'll be called when you need to regenerate the
  64. password.
  65. """
  66. is_correct, must_update = verify_password(password, encoded, preferred=preferred)
  67. if setter and is_correct and must_update:
  68. setter(password)
  69. return is_correct
  70. async def acheck_password(password, encoded, setter=None, preferred="default"):
  71. """See check_password()."""
  72. is_correct, must_update = verify_password(password, encoded, preferred=preferred)
  73. if setter and is_correct and must_update:
  74. await setter(password)
  75. return is_correct
  76. def make_password(password, salt=None, hasher="default"):
  77. """
  78. Turn a plain-text password into a hash for database storage
  79. Same as encode() but generate a new random salt. If password is None then
  80. return a concatenation of UNUSABLE_PASSWORD_PREFIX and a random string,
  81. which disallows logins. Additional random string reduces chances of gaining
  82. access to staff or superuser accounts. See ticket #20079 for more info.
  83. """
  84. if password is None:
  85. return UNUSABLE_PASSWORD_PREFIX + get_random_string(
  86. UNUSABLE_PASSWORD_SUFFIX_LENGTH
  87. )
  88. if not isinstance(password, (bytes, str)):
  89. raise TypeError(
  90. "Password must be a string or bytes, got %s." % type(password).__qualname__
  91. )
  92. hasher = get_hasher(hasher)
  93. salt = salt or hasher.salt()
  94. return hasher.encode(password, salt)
  95. @functools.lru_cache
  96. def get_hashers():
  97. hashers = []
  98. for hasher_path in settings.PASSWORD_HASHERS:
  99. hasher_cls = import_string(hasher_path)
  100. hasher = hasher_cls()
  101. if not getattr(hasher, "algorithm"):
  102. raise ImproperlyConfigured(
  103. "hasher doesn't specify an algorithm name: %s" % hasher_path
  104. )
  105. hashers.append(hasher)
  106. return hashers
  107. @functools.lru_cache
  108. def get_hashers_by_algorithm():
  109. return {hasher.algorithm: hasher for hasher in get_hashers()}
  110. @receiver(setting_changed)
  111. def reset_hashers(*, setting, **kwargs):
  112. if setting == "PASSWORD_HASHERS":
  113. get_hashers.cache_clear()
  114. get_hashers_by_algorithm.cache_clear()
  115. def get_hasher(algorithm="default"):
  116. """
  117. Return an instance of a loaded password hasher.
  118. If algorithm is 'default', return the default hasher. Lazily import hashers
  119. specified in the project's settings file if needed.
  120. """
  121. if hasattr(algorithm, "algorithm"):
  122. return algorithm
  123. elif algorithm == "default":
  124. return get_hashers()[0]
  125. else:
  126. hashers = get_hashers_by_algorithm()
  127. try:
  128. return hashers[algorithm]
  129. except KeyError:
  130. raise ValueError(
  131. "Unknown password hashing algorithm '%s'. "
  132. "Did you specify it in the PASSWORD_HASHERS "
  133. "setting?" % algorithm
  134. )
  135. def identify_hasher(encoded):
  136. """
  137. Return an instance of a loaded password hasher.
  138. Identify hasher algorithm by examining encoded hash, and call
  139. get_hasher() to return hasher. Raise ValueError if
  140. algorithm cannot be identified, or if hasher is not loaded.
  141. """
  142. # Ancient versions of Django created plain MD5 passwords and accepted
  143. # MD5 passwords with an empty salt.
  144. if (len(encoded) == 32 and "$" not in encoded) or (
  145. len(encoded) == 37 and encoded.startswith("md5$$")
  146. ):
  147. algorithm = "unsalted_md5"
  148. # Ancient versions of Django accepted SHA1 passwords with an empty salt.
  149. elif len(encoded) == 46 and encoded.startswith("sha1$$"):
  150. algorithm = "unsalted_sha1"
  151. else:
  152. algorithm = encoded.split("$", 1)[0]
  153. return get_hasher(algorithm)
  154. def mask_hash(hash, show=6, char="*"):
  155. """
  156. Return the given hash, with only the first ``show`` number shown. The
  157. rest are masked with ``char`` for security reasons.
  158. """
  159. masked = hash[:show]
  160. masked += char * len(hash[show:])
  161. return masked
  162. def must_update_salt(salt, expected_entropy):
  163. # Each character in the salt provides log_2(len(alphabet)) bits of entropy.
  164. return len(salt) * math.log2(len(RANDOM_STRING_CHARS)) < expected_entropy
  165. class BasePasswordHasher:
  166. """
  167. Abstract base class for password hashers
  168. When creating your own hasher, you need to override algorithm,
  169. verify(), encode() and safe_summary().
  170. PasswordHasher objects are immutable.
  171. """
  172. algorithm = None
  173. library = None
  174. salt_entropy = 128
  175. def _load_library(self):
  176. if self.library is not None:
  177. if isinstance(self.library, (tuple, list)):
  178. name, mod_path = self.library
  179. else:
  180. mod_path = self.library
  181. try:
  182. module = importlib.import_module(mod_path)
  183. except ImportError as e:
  184. raise ValueError(
  185. "Couldn't load %r algorithm library: %s"
  186. % (self.__class__.__name__, e)
  187. )
  188. return module
  189. raise ValueError(
  190. "Hasher %r doesn't specify a library attribute" % self.__class__.__name__
  191. )
  192. def salt(self):
  193. """
  194. Generate a cryptographically secure nonce salt in ASCII with an entropy
  195. of at least `salt_entropy` bits.
  196. """
  197. # Each character in the salt provides
  198. # log_2(len(alphabet)) bits of entropy.
  199. char_count = math.ceil(self.salt_entropy / math.log2(len(RANDOM_STRING_CHARS)))
  200. return get_random_string(char_count, allowed_chars=RANDOM_STRING_CHARS)
  201. def verify(self, password, encoded):
  202. """Check if the given password is correct."""
  203. raise NotImplementedError(
  204. "subclasses of BasePasswordHasher must provide a verify() method"
  205. )
  206. def _check_encode_args(self, password, salt):
  207. if password is None:
  208. raise TypeError("password must be provided.")
  209. if not salt or "$" in salt:
  210. raise ValueError("salt must be provided and cannot contain $.")
  211. def encode(self, password, salt):
  212. """
  213. Create an encoded database value.
  214. The result is normally formatted as "algorithm$salt$hash" and
  215. must be fewer than 128 characters.
  216. """
  217. raise NotImplementedError(
  218. "subclasses of BasePasswordHasher must provide an encode() method"
  219. )
  220. def decode(self, encoded):
  221. """
  222. Return a decoded database value.
  223. The result is a dictionary and should contain `algorithm`, `hash`, and
  224. `salt`. Extra keys can be algorithm specific like `iterations` or
  225. `work_factor`.
  226. """
  227. raise NotImplementedError(
  228. "subclasses of BasePasswordHasher must provide a decode() method."
  229. )
  230. def safe_summary(self, encoded):
  231. """
  232. Return a summary of safe values.
  233. The result is a dictionary and will be used where the password field
  234. must be displayed to construct a safe representation of the password.
  235. """
  236. raise NotImplementedError(
  237. "subclasses of BasePasswordHasher must provide a safe_summary() method"
  238. )
  239. def must_update(self, encoded):
  240. return False
  241. def harden_runtime(self, password, encoded):
  242. """
  243. Bridge the runtime gap between the work factor supplied in `encoded`
  244. and the work factor suggested by this hasher.
  245. Taking PBKDF2 as an example, if `encoded` contains 20000 iterations and
  246. `self.iterations` is 30000, this method should run password through
  247. another 10000 iterations of PBKDF2. Similar approaches should exist
  248. for any hasher that has a work factor. If not, this method should be
  249. defined as a no-op to silence the warning.
  250. """
  251. warnings.warn(
  252. "subclasses of BasePasswordHasher should provide a harden_runtime() method"
  253. )
  254. class PBKDF2PasswordHasher(BasePasswordHasher):
  255. """
  256. Secure password hashing using the PBKDF2 algorithm (recommended)
  257. Configured to use PBKDF2 + HMAC + SHA256.
  258. The result is a 64 byte binary string. Iterations may be changed
  259. safely but you must rename the algorithm if you change SHA256.
  260. """
  261. algorithm = "pbkdf2_sha256"
  262. iterations = 870000
  263. digest = hashlib.sha256
  264. def encode(self, password, salt, iterations=None):
  265. self._check_encode_args(password, salt)
  266. iterations = iterations or self.iterations
  267. hash = pbkdf2(password, salt, iterations, digest=self.digest)
  268. hash = base64.b64encode(hash).decode("ascii").strip()
  269. return "%s$%d$%s$%s" % (self.algorithm, iterations, salt, hash)
  270. def decode(self, encoded):
  271. algorithm, iterations, salt, hash = encoded.split("$", 3)
  272. assert algorithm == self.algorithm
  273. return {
  274. "algorithm": algorithm,
  275. "hash": hash,
  276. "iterations": int(iterations),
  277. "salt": salt,
  278. }
  279. def verify(self, password, encoded):
  280. decoded = self.decode(encoded)
  281. encoded_2 = self.encode(password, decoded["salt"], decoded["iterations"])
  282. return constant_time_compare(encoded, encoded_2)
  283. def safe_summary(self, encoded):
  284. decoded = self.decode(encoded)
  285. return {
  286. _("algorithm"): decoded["algorithm"],
  287. _("iterations"): decoded["iterations"],
  288. _("salt"): mask_hash(decoded["salt"]),
  289. _("hash"): mask_hash(decoded["hash"]),
  290. }
  291. def must_update(self, encoded):
  292. decoded = self.decode(encoded)
  293. update_salt = must_update_salt(decoded["salt"], self.salt_entropy)
  294. return (decoded["iterations"] != self.iterations) or update_salt
  295. def harden_runtime(self, password, encoded):
  296. decoded = self.decode(encoded)
  297. extra_iterations = self.iterations - decoded["iterations"]
  298. if extra_iterations > 0:
  299. self.encode(password, decoded["salt"], extra_iterations)
  300. class PBKDF2SHA1PasswordHasher(PBKDF2PasswordHasher):
  301. """
  302. Alternate PBKDF2 hasher which uses SHA1, the default PRF
  303. recommended by PKCS #5. This is compatible with other
  304. implementations of PBKDF2, such as openssl's
  305. PKCS5_PBKDF2_HMAC_SHA1().
  306. """
  307. algorithm = "pbkdf2_sha1"
  308. digest = hashlib.sha1
  309. class Argon2PasswordHasher(BasePasswordHasher):
  310. """
  311. Secure password hashing using the argon2 algorithm.
  312. This is the winner of the Password Hashing Competition 2013-2015
  313. (https://password-hashing.net). It requires the argon2-cffi library which
  314. depends on native C code and might cause portability issues.
  315. """
  316. algorithm = "argon2"
  317. library = "argon2"
  318. time_cost = 2
  319. memory_cost = 102400
  320. parallelism = 8
  321. def encode(self, password, salt):
  322. argon2 = self._load_library()
  323. params = self.params()
  324. data = argon2.low_level.hash_secret(
  325. password.encode(),
  326. salt.encode(),
  327. time_cost=params.time_cost,
  328. memory_cost=params.memory_cost,
  329. parallelism=params.parallelism,
  330. hash_len=params.hash_len,
  331. type=params.type,
  332. )
  333. return self.algorithm + data.decode("ascii")
  334. def decode(self, encoded):
  335. argon2 = self._load_library()
  336. algorithm, rest = encoded.split("$", 1)
  337. assert algorithm == self.algorithm
  338. params = argon2.extract_parameters("$" + rest)
  339. variety, *_, b64salt, hash = rest.split("$")
  340. # Add padding.
  341. b64salt += "=" * (-len(b64salt) % 4)
  342. salt = base64.b64decode(b64salt).decode("latin1")
  343. return {
  344. "algorithm": algorithm,
  345. "hash": hash,
  346. "memory_cost": params.memory_cost,
  347. "parallelism": params.parallelism,
  348. "salt": salt,
  349. "time_cost": params.time_cost,
  350. "variety": variety,
  351. "version": params.version,
  352. "params": params,
  353. }
  354. def verify(self, password, encoded):
  355. argon2 = self._load_library()
  356. algorithm, rest = encoded.split("$", 1)
  357. assert algorithm == self.algorithm
  358. try:
  359. return argon2.PasswordHasher().verify("$" + rest, password)
  360. except argon2.exceptions.VerificationError:
  361. return False
  362. def safe_summary(self, encoded):
  363. decoded = self.decode(encoded)
  364. return {
  365. _("algorithm"): decoded["algorithm"],
  366. _("variety"): decoded["variety"],
  367. _("version"): decoded["version"],
  368. _("memory cost"): decoded["memory_cost"],
  369. _("time cost"): decoded["time_cost"],
  370. _("parallelism"): decoded["parallelism"],
  371. _("salt"): mask_hash(decoded["salt"]),
  372. _("hash"): mask_hash(decoded["hash"]),
  373. }
  374. def must_update(self, encoded):
  375. decoded = self.decode(encoded)
  376. current_params = decoded["params"]
  377. new_params = self.params()
  378. # Set salt_len to the salt_len of the current parameters because salt
  379. # is explicitly passed to argon2.
  380. new_params.salt_len = current_params.salt_len
  381. update_salt = must_update_salt(decoded["salt"], self.salt_entropy)
  382. return (current_params != new_params) or update_salt
  383. def harden_runtime(self, password, encoded):
  384. # The runtime for Argon2 is too complicated to implement a sensible
  385. # hardening algorithm.
  386. pass
  387. def params(self):
  388. argon2 = self._load_library()
  389. # salt_len is a noop, because we provide our own salt.
  390. return argon2.Parameters(
  391. type=argon2.low_level.Type.ID,
  392. version=argon2.low_level.ARGON2_VERSION,
  393. salt_len=argon2.DEFAULT_RANDOM_SALT_LENGTH,
  394. hash_len=argon2.DEFAULT_HASH_LENGTH,
  395. time_cost=self.time_cost,
  396. memory_cost=self.memory_cost,
  397. parallelism=self.parallelism,
  398. )
  399. class BCryptSHA256PasswordHasher(BasePasswordHasher):
  400. """
  401. Secure password hashing using the bcrypt algorithm (recommended)
  402. This is considered by many to be the most secure algorithm but you
  403. must first install the bcrypt library. Please be warned that
  404. this library depends on native C code and might cause portability
  405. issues.
  406. """
  407. algorithm = "bcrypt_sha256"
  408. digest = hashlib.sha256
  409. library = ("bcrypt", "bcrypt")
  410. rounds = 12
  411. def salt(self):
  412. bcrypt = self._load_library()
  413. return bcrypt.gensalt(self.rounds)
  414. def encode(self, password, salt):
  415. bcrypt = self._load_library()
  416. password = password.encode()
  417. # Hash the password prior to using bcrypt to prevent password
  418. # truncation as described in #20138.
  419. if self.digest is not None:
  420. # Use binascii.hexlify() because a hex encoded bytestring is str.
  421. password = binascii.hexlify(self.digest(password).digest())
  422. data = bcrypt.hashpw(password, salt)
  423. return "%s$%s" % (self.algorithm, data.decode("ascii"))
  424. def decode(self, encoded):
  425. algorithm, empty, algostr, work_factor, data = encoded.split("$", 4)
  426. assert algorithm == self.algorithm
  427. return {
  428. "algorithm": algorithm,
  429. "algostr": algostr,
  430. "checksum": data[22:],
  431. "salt": data[:22],
  432. "work_factor": int(work_factor),
  433. }
  434. def verify(self, password, encoded):
  435. algorithm, data = encoded.split("$", 1)
  436. assert algorithm == self.algorithm
  437. encoded_2 = self.encode(password, data.encode("ascii"))
  438. return constant_time_compare(encoded, encoded_2)
  439. def safe_summary(self, encoded):
  440. decoded = self.decode(encoded)
  441. return {
  442. _("algorithm"): decoded["algorithm"],
  443. _("work factor"): decoded["work_factor"],
  444. _("salt"): mask_hash(decoded["salt"]),
  445. _("checksum"): mask_hash(decoded["checksum"]),
  446. }
  447. def must_update(self, encoded):
  448. decoded = self.decode(encoded)
  449. return decoded["work_factor"] != self.rounds
  450. def harden_runtime(self, password, encoded):
  451. _, data = encoded.split("$", 1)
  452. salt = data[:29] # Length of the salt in bcrypt.
  453. rounds = data.split("$")[2]
  454. # work factor is logarithmic, adding one doubles the load.
  455. diff = 2 ** (self.rounds - int(rounds)) - 1
  456. while diff > 0:
  457. self.encode(password, salt.encode("ascii"))
  458. diff -= 1
  459. class BCryptPasswordHasher(BCryptSHA256PasswordHasher):
  460. """
  461. Secure password hashing using the bcrypt algorithm
  462. This is considered by many to be the most secure algorithm but you
  463. must first install the bcrypt library. Please be warned that
  464. this library depends on native C code and might cause portability
  465. issues.
  466. This hasher does not first hash the password which means it is subject to
  467. bcrypt's 72 bytes password truncation. Most use cases should prefer the
  468. BCryptSHA256PasswordHasher.
  469. """
  470. algorithm = "bcrypt"
  471. digest = None
  472. class ScryptPasswordHasher(BasePasswordHasher):
  473. """
  474. Secure password hashing using the Scrypt algorithm.
  475. """
  476. algorithm = "scrypt"
  477. block_size = 8
  478. maxmem = 0
  479. parallelism = 5
  480. work_factor = 2**14
  481. def encode(self, password, salt, n=None, r=None, p=None):
  482. self._check_encode_args(password, salt)
  483. n = n or self.work_factor
  484. r = r or self.block_size
  485. p = p or self.parallelism
  486. hash_ = hashlib.scrypt(
  487. password.encode(),
  488. salt=salt.encode(),
  489. n=n,
  490. r=r,
  491. p=p,
  492. maxmem=self.maxmem,
  493. dklen=64,
  494. )
  495. hash_ = base64.b64encode(hash_).decode("ascii").strip()
  496. return "%s$%d$%s$%d$%d$%s" % (self.algorithm, n, salt, r, p, hash_)
  497. def decode(self, encoded):
  498. algorithm, work_factor, salt, block_size, parallelism, hash_ = encoded.split(
  499. "$", 6
  500. )
  501. assert algorithm == self.algorithm
  502. return {
  503. "algorithm": algorithm,
  504. "work_factor": int(work_factor),
  505. "salt": salt,
  506. "block_size": int(block_size),
  507. "parallelism": int(parallelism),
  508. "hash": hash_,
  509. }
  510. def verify(self, password, encoded):
  511. decoded = self.decode(encoded)
  512. encoded_2 = self.encode(
  513. password,
  514. decoded["salt"],
  515. decoded["work_factor"],
  516. decoded["block_size"],
  517. decoded["parallelism"],
  518. )
  519. return constant_time_compare(encoded, encoded_2)
  520. def safe_summary(self, encoded):
  521. decoded = self.decode(encoded)
  522. return {
  523. _("algorithm"): decoded["algorithm"],
  524. _("work factor"): decoded["work_factor"],
  525. _("block size"): decoded["block_size"],
  526. _("parallelism"): decoded["parallelism"],
  527. _("salt"): mask_hash(decoded["salt"]),
  528. _("hash"): mask_hash(decoded["hash"]),
  529. }
  530. def must_update(self, encoded):
  531. decoded = self.decode(encoded)
  532. return (
  533. decoded["work_factor"] != self.work_factor
  534. or decoded["block_size"] != self.block_size
  535. or decoded["parallelism"] != self.parallelism
  536. )
  537. def harden_runtime(self, password, encoded):
  538. # The runtime for Scrypt is too complicated to implement a sensible
  539. # hardening algorithm.
  540. pass
  541. class MD5PasswordHasher(BasePasswordHasher):
  542. """
  543. The Salted MD5 password hashing algorithm (not recommended)
  544. """
  545. algorithm = "md5"
  546. def encode(self, password, salt):
  547. self._check_encode_args(password, salt)
  548. hash = hashlib.md5((salt + password).encode()).hexdigest()
  549. return "%s$%s$%s" % (self.algorithm, salt, hash)
  550. def decode(self, encoded):
  551. algorithm, salt, hash = encoded.split("$", 2)
  552. assert algorithm == self.algorithm
  553. return {
  554. "algorithm": algorithm,
  555. "hash": hash,
  556. "salt": salt,
  557. }
  558. def verify(self, password, encoded):
  559. decoded = self.decode(encoded)
  560. encoded_2 = self.encode(password, decoded["salt"])
  561. return constant_time_compare(encoded, encoded_2)
  562. def safe_summary(self, encoded):
  563. decoded = self.decode(encoded)
  564. return {
  565. _("algorithm"): decoded["algorithm"],
  566. _("salt"): mask_hash(decoded["salt"], show=2),
  567. _("hash"): mask_hash(decoded["hash"]),
  568. }
  569. def must_update(self, encoded):
  570. decoded = self.decode(encoded)
  571. return must_update_salt(decoded["salt"], self.salt_entropy)
  572. def harden_runtime(self, password, encoded):
  573. pass