| 484 | """ |
| 485 | |
| 486 | def authenticate( |
| 487 | self, |
| 488 | request: HttpRequest | None, |
| 489 | username: str | None = None, |
| 490 | password: str | None = None, |
| 491 | **kwargs: Any, |
| 492 | ) -> User | None: |
| 493 | for user in find_users(username): |
| 494 | try: |
| 495 | if is_demo_mode_enabled() and is_demo_user(user): |
| 496 | return user |
| 497 | if user.password: |
| 498 | # XXX(joshuarli): This is checked before (and therefore, regardless of outcome) |
| 499 | # password checking as a mechanism to drop old password hashers immediately and |
| 500 | # then lazily sending out password reset emails. |
| 501 | if user.is_password_expired: |
| 502 | raise AuthUserPasswordExpired(user) |
| 503 | if password is not None and user.check_password(password): |
| 504 | return user |
| 505 | except ValueError: |
| 506 | continue |
| 507 | return None |
| 508 | |
| 509 | def user_can_authenticate(self, user: User | AnonymousUser | None) -> bool: |
| 510 | return True |