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