mirror of https://github.com/django/django.git
Refs #33764 -- Removed BaseUserManager.make_random_password() per deprecation timeline.
This commit is contained in:
parent
295467c04a
commit
00e1879610
|
@ -3,7 +3,6 @@ This module allows importing AbstractBaseUser even when django.contrib.auth is
|
|||
not in INSTALLED_APPS.
|
||||
"""
|
||||
import unicodedata
|
||||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import password_validation
|
||||
|
@ -14,8 +13,7 @@ from django.contrib.auth.hashers import (
|
|||
make_password,
|
||||
)
|
||||
from django.db import models
|
||||
from django.utils.crypto import get_random_string, salted_hmac
|
||||
from django.utils.deprecation import RemovedInDjango51Warning
|
||||
from django.utils.crypto import salted_hmac
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
|
@ -34,23 +32,6 @@ class BaseUserManager(models.Manager):
|
|||
email = email_name + "@" + domain_part.lower()
|
||||
return email
|
||||
|
||||
def make_random_password(
|
||||
self,
|
||||
length=10,
|
||||
allowed_chars="abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789",
|
||||
):
|
||||
"""
|
||||
Generate a random password with the given length and given
|
||||
allowed_chars. The default value of allowed_chars does not have "I" or
|
||||
"O" or letters and digits that look similar -- just to avoid confusion.
|
||||
"""
|
||||
warnings.warn(
|
||||
"BaseUserManager.make_random_password() is deprecated.",
|
||||
category=RemovedInDjango51Warning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return get_random_string(length, allowed_chars)
|
||||
|
||||
def get_by_natural_key(self, username):
|
||||
return self.get(**{self.model.USERNAME_FIELD: username})
|
||||
|
||||
|
|
|
@ -251,4 +251,4 @@ in Django 5.1.
|
|||
See :ref:`deprecated-features-4.2` for details on these changes, including how
|
||||
to remove usage of these features.
|
||||
|
||||
* ...
|
||||
* The ``BaseUserManager.make_random_password()`` method is removed.
|
||||
|
|
|
@ -799,19 +799,6 @@ utility methods:
|
|||
Retrieves a user instance using the contents of the field
|
||||
nominated by ``USERNAME_FIELD``.
|
||||
|
||||
.. method:: models.BaseUserManager.make_random_password(length=10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
|
||||
|
||||
.. deprecated:: 4.2
|
||||
|
||||
Returns a random password with the given length and given string of
|
||||
allowed characters. Note that the default value of ``allowed_chars``
|
||||
doesn't contain letters that can cause user confusion, including:
|
||||
|
||||
* ``i``, ``l``, ``I``, and ``1`` (lowercase letter i, lowercase
|
||||
letter L, uppercase letter i, and the number one)
|
||||
* ``o``, ``O``, and ``0`` (lowercase letter o, uppercase letter o,
|
||||
and zero)
|
||||
|
||||
Extending Django's default ``User``
|
||||
-----------------------------------
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@ from django.db import connection, migrations
|
|||
from django.db.migrations.state import ModelState, ProjectState
|
||||
from django.db.models.signals import post_save
|
||||
from django.test import SimpleTestCase, TestCase, TransactionTestCase, override_settings
|
||||
from django.test.utils import ignore_warnings
|
||||
from django.utils.deprecation import RemovedInDjango51Warning
|
||||
|
||||
from .models import CustomEmailField, IntegerUsernameUser
|
||||
|
||||
|
@ -168,19 +166,6 @@ class UserManagerTestCase(TransactionTestCase):
|
|||
is_staff=False,
|
||||
)
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango51Warning)
|
||||
def test_make_random_password(self):
|
||||
allowed_chars = "abcdefg"
|
||||
password = UserManager().make_random_password(5, allowed_chars)
|
||||
self.assertEqual(len(password), 5)
|
||||
for char in password:
|
||||
self.assertIn(char, allowed_chars)
|
||||
|
||||
def test_make_random_password_warning(self):
|
||||
msg = "BaseUserManager.make_random_password() is deprecated."
|
||||
with self.assertWarnsMessage(RemovedInDjango51Warning, msg):
|
||||
UserManager().make_random_password()
|
||||
|
||||
def test_runpython_manager_methods(self):
|
||||
def forwards(apps, schema_editor):
|
||||
UserModel = apps.get_model("auth", "User")
|
||||
|
|
Loading…
Reference in New Issue