Plain is headed towards 1.0! Subscribe for development updates →

 1from __future__ import annotations
 2
 3from typing import Any
 4
 5from .hashers import check_password, hash_password
 6
 7
 8def check_user_password(user: Any, password: str) -> bool:
 9    # Run the default password hasher once to reduce the timing
10    # difference between an existing and a nonexistent user (#20760).
11    hash_password(password)
12
13    # Update the stored hashed password if the hashing algorithm changed
14    def setter(raw_password: str) -> None:
15        user.password = raw_password
16        user.save(update_fields=["password"])
17
18    password_is_correct = check_password(password, user.password, setter)
19
20    return password_is_correct