diff --git a/django/contrib/admin/static/admin/css/unusable_password_field.css b/django/contrib/admin/static/admin/css/unusable_password_field.css
new file mode 100644
index 0000000000..d46eb0384c
--- /dev/null
+++ b/django/contrib/admin/static/admin/css/unusable_password_field.css
@@ -0,0 +1,19 @@
+/* Hide warnings fields if usable password is selected */
+form:has(#id_usable_password input[value="true"]:checked) .messagelist {
+ display: none;
+}
+
+/* Hide password fields if unusable password is selected */
+form:has(#id_usable_password input[value="false"]:checked) .field-password1,
+form:has(#id_usable_password input[value="false"]:checked) .field-password2 {
+ display: none;
+}
+
+/* Select appropriate submit button */
+form:has(#id_usable_password input[value="true"]:checked) input[type="submit"].unset-password {
+ display: none;
+}
+
+form:has(#id_usable_password input[value="false"]:checked) input[type="submit"].set-password {
+ display: none;
+}
diff --git a/django/contrib/admin/static/admin/js/unusable_password_field.js b/django/contrib/admin/static/admin/js/unusable_password_field.js
new file mode 100644
index 0000000000..ec26238c29
--- /dev/null
+++ b/django/contrib/admin/static/admin/js/unusable_password_field.js
@@ -0,0 +1,29 @@
+"use strict";
+// Fallback JS for browsers which do not support :has selector used in
+// admin/css/unusable_password_fields.css
+// Remove file once all supported browsers support :has selector
+try {
+ // If browser does not support :has selector this will raise an error
+ document.querySelector("form:has(input)");
+} catch (error) {
+ console.log("Defaulting to javascript for usable password form management: " + error);
+ // JS replacement for unsupported :has selector
+ document.querySelectorAll('input[name="usable_password"]').forEach(option => {
+ option.addEventListener('change', function() {
+ const usablePassword = (this.value === "true" ? this.checked : !this.checked);
+ const submit1 = document.querySelector('input[type="submit"].set-password');
+ const submit2 = document.querySelector('input[type="submit"].unset-password');
+ const messages = document.querySelector('#id_unusable_warning');
+ document.getElementById('id_password1').closest('.form-row').hidden = !usablePassword;
+ document.getElementById('id_password2').closest('.form-row').hidden = !usablePassword;
+ if (messages) {
+ messages.hidden = usablePassword;
+ }
+ if (submit1 && submit2) {
+ submit1.hidden = !usablePassword;
+ submit2.hidden = usablePassword;
+ }
+ });
+ option.dispatchEvent(new Event('change'));
+ });
+}
diff --git a/django/contrib/admin/templates/admin/auth/user/add_form.html b/django/contrib/admin/templates/admin/auth/user/add_form.html
index 61cf5b1b40..48406f11a2 100644
--- a/django/contrib/admin/templates/admin/auth/user/add_form.html
+++ b/django/contrib/admin/templates/admin/auth/user/add_form.html
@@ -1,5 +1,5 @@
{% extends "admin/change_form.html" %}
-{% load i18n %}
+{% load i18n static %}
{% block form_top %}
{% if not is_popup %}
@@ -8,3 +8,11 @@
{% translate "Enter a username and password." %}
{% endif %}
{% endblock %}
+{% block extrahead %}
+ {{ block.super }}
+
+{% endblock %}
+{% block admin_change_form_document_ready %}
+ {{ block.super }}
+
+{% endblock %}
diff --git a/django/contrib/admin/templates/admin/auth/user/change_password.html b/django/contrib/admin/templates/admin/auth/user/change_password.html
index ebb24ef562..6801fe5fa7 100644
--- a/django/contrib/admin/templates/admin/auth/user/change_password.html
+++ b/django/contrib/admin/templates/admin/auth/user/change_password.html
@@ -2,7 +2,11 @@
{% load i18n static %}
{% load admin_urls %}
-{% block extrastyle %}{{ block.super }}{% endblock %}
+{% block extrastyle %}
+ {{ block.super }}
+
+
+{% endblock %}
{% block bodyclass %}{{ block.super }} {{ opts.app_label }}-{{ opts.model_name }} change-form{% endblock %}
{% if not is_popup %}
{% block breadcrumbs %}
@@ -11,7 +15,7 @@
› {{ opts.app_config.verbose_name }}
› {{ opts.verbose_name_plural|capfirst }}
› {{ original|truncatewords:"18" }}
-› {% translate 'Change password' %}
+› {% if form.user.has_usable_password %}{% translate 'Change password' %}{% else %}{% translate 'Set password' %}{% endif %}
{% endblock %}
{% endif %}
@@ -27,10 +31,23 @@
{% endif %}
{% blocktranslate with username=original %}Enter a new password for the user {{ username }}.{% endblocktranslate %}
+{% if not form.user.has_usable_password %}
+ {% blocktranslate %}This action will enable password-based authentication for this user.{% endblocktranslate %}
+{% endif %}