Skip to content

Commit f2d9c76

Browse files
committed
Refs #33764 -- Removed BaseUserManager.make_random_password() per deprecation timeline.
1 parent 9edb783 commit f2d9c76

File tree

4 files changed

+2
-49
lines changed

4 files changed

+2
-49
lines changed

django/contrib/auth/base_user.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
not in INSTALLED_APPS.
44
"""
55
import unicodedata
6-
import warnings
76

87
from django.conf import settings
98
from django.contrib.auth import password_validation
@@ -14,8 +13,7 @@
1413
make_password,
1514
)
1615
from django.db import models
17-
from django.utils.crypto import get_random_string, salted_hmac
18-
from django.utils.deprecation import RemovedInDjango51Warning
16+
from django.utils.crypto import salted_hmac
1917
from django.utils.translation import gettext_lazy as _
2018

2119

@@ -34,23 +32,6 @@ def normalize_email(cls, email):
3432
email = email_name + "@" + domain_part.lower()
3533
return email
3634

37-
def make_random_password(
38-
self,
39-
length=10,
40-
allowed_chars="abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789",
41-
):
42-
"""
43-
Generate a random password with the given length and given
44-
allowed_chars. The default value of allowed_chars does not have "I" or
45-
"O" or letters and digits that look similar -- just to avoid confusion.
46-
"""
47-
warnings.warn(
48-
"BaseUserManager.make_random_password() is deprecated.",
49-
category=RemovedInDjango51Warning,
50-
stacklevel=2,
51-
)
52-
return get_random_string(length, allowed_chars)
53-
5435
def get_by_natural_key(self, username):
5536
return self.get(**{self.model.USERNAME_FIELD: username})
5637

docs/releases/5.1.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,4 @@ in Django 5.1.
251251
See :ref:`deprecated-features-4.2` for details on these changes, including how
252252
to remove usage of these features.
253253

254-
* ...
254+
* The ``BaseUserManager.make_random_password()`` method is removed.

docs/topics/auth/customizing.txt

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -799,19 +799,6 @@ utility methods:
799799
Retrieves a user instance using the contents of the field
800800
nominated by ``USERNAME_FIELD``.
801801

802-
.. method:: models.BaseUserManager.make_random_password(length=10, allowed_chars='abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789')
803-
804-
.. deprecated:: 4.2
805-
806-
Returns a random password with the given length and given string of
807-
allowed characters. Note that the default value of ``allowed_chars``
808-
doesn't contain letters that can cause user confusion, including:
809-
810-
* ``i``, ``l``, ``I``, and ``1`` (lowercase letter i, lowercase
811-
letter L, uppercase letter i, and the number one)
812-
* ``o``, ``O``, and ``0`` (lowercase letter o, uppercase letter o,
813-
and zero)
814-
815802
Extending Django's default ``User``
816803
-----------------------------------
817804

tests/auth_tests/test_models.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
from django.db.migrations.state import ModelState, ProjectState
2121
from django.db.models.signals import post_save
2222
from django.test import SimpleTestCase, TestCase, TransactionTestCase, override_settings
23-
from django.test.utils import ignore_warnings
24-
from django.utils.deprecation import RemovedInDjango51Warning
2523

2624
from .models import CustomEmailField, IntegerUsernameUser
2725

@@ -168,19 +166,6 @@ def test_create_superuser_raises_error_on_false_is_staff(self):
168166
is_staff=False,
169167
)
170168

171-
@ignore_warnings(category=RemovedInDjango51Warning)
172-
def test_make_random_password(self):
173-
allowed_chars = "abcdefg"
174-
password = UserManager().make_random_password(5, allowed_chars)
175-
self.assertEqual(len(password), 5)
176-
for char in password:
177-
self.assertIn(char, allowed_chars)
178-
179-
def test_make_random_password_warning(self):
180-
msg = "BaseUserManager.make_random_password() is deprecated."
181-
with self.assertWarnsMessage(RemovedInDjango51Warning, msg):
182-
UserManager().make_random_password()
183-
184169
def test_runpython_manager_methods(self):
185170
def forwards(apps, schema_editor):
186171
UserModel = apps.get_model("auth", "User")

0 commit comments

Comments
 (0)