diff options
| author | django-bot <ops@djangoproject.com> | 2022-02-03 20:24:19 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-02-07 20:37:05 +0100 |
| commit | 9c19aff7c7561e3a82978a272ecdaad40dda5c00 (patch) | |
| tree | f0506b668a013d0063e5fba3dbf4863b466713ba /django/contrib/auth/base_user.py | |
| parent | f68fa8b45dfac545cfc4111d4e52804c86db68d3 (diff) | |
Refs #33476 -- Reformatted code with Black.
Diffstat (limited to 'django/contrib/auth/base_user.py')
| -rw-r--r-- | django/contrib/auth/base_user.py | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/django/contrib/auth/base_user.py b/django/contrib/auth/base_user.py index cbfe5d686a..f6de3b9317 100644 --- a/django/contrib/auth/base_user.py +++ b/django/contrib/auth/base_user.py @@ -6,7 +6,9 @@ import unicodedata from django.contrib.auth import password_validation from django.contrib.auth.hashers import ( - check_password, is_password_usable, make_password, + check_password, + is_password_usable, + make_password, ) from django.db import models from django.utils.crypto import get_random_string, salted_hmac @@ -14,25 +16,24 @@ from django.utils.translation import gettext_lazy as _ class BaseUserManager(models.Manager): - @classmethod def normalize_email(cls, email): """ Normalize the email address by lowercasing the domain part of it. """ - email = email or '' + email = email or "" try: - email_name, domain_part = email.strip().rsplit('@', 1) + email_name, domain_part = email.strip().rsplit("@", 1) except ValueError: pass else: - email = email_name + '@' + domain_part.lower() + email = email_name + "@" + domain_part.lower() return email def make_random_password( self, length=10, - allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789', + allowed_chars="abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789", ): """ Generate a random password with the given length and given @@ -46,8 +47,8 @@ class BaseUserManager(models.Manager): class AbstractBaseUser(models.Model): - password = models.CharField(_('password'), max_length=128) - last_login = models.DateTimeField(_('last login'), blank=True, null=True) + password = models.CharField(_("password"), max_length=128) + last_login = models.DateTimeField(_("last login"), blank=True, null=True) is_active = True @@ -104,11 +105,13 @@ class AbstractBaseUser(models.Model): Return a boolean of whether the raw_password was correct. Handles hashing formats behind the scenes. """ + def setter(raw_password): self.set_password(raw_password) # Password hash upgrades shouldn't be considered password changes. self._password = None self.save(update_fields=["password"]) + return check_password(raw_password, self.password, setter) def set_unusable_password(self): @@ -129,7 +132,7 @@ class AbstractBaseUser(models.Model): return salted_hmac( key_salt, self.password, - algorithm='sha256', + algorithm="sha256", ).hexdigest() @classmethod @@ -137,8 +140,12 @@ class AbstractBaseUser(models.Model): try: return cls.EMAIL_FIELD except AttributeError: - return 'email' + return "email" @classmethod def normalize_username(cls, username): - return unicodedata.normalize('NFKC', username) if isinstance(username, str) else username + return ( + unicodedata.normalize("NFKC", username) + if isinstance(username, str) + else username + ) |
