From e3d280ffd8e8397af85f7bd3478bfe73e7d50efb Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Sat, 10 Oct 2020 16:51:07 +0000 Subject: [PATCH] Users: prevent saving empty passwords, trim space from password ends on save. Fix an issue where users could save a password with only spaces, or spaces at the beginning or end of their password, preventing them from logging in. Props ronakganatra, 1naveengiri, ajensen, oolleegg55, bookdude13, nrqsnchz, aristath. Fixes #42766. Built from https://develop.svn.wordpress.org/trunk@49118 git-svn-id: http://core.svn.wordpress.org/trunk@48880 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/user.php | 4 ++-- wp-admin/js/user-profile.js | 2 +- wp-admin/js/user-profile.min.js | 2 +- wp-includes/version.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/wp-admin/includes/user.php b/wp-admin/includes/user.php index de7cb989c1..5fbfd9f9b4 100644 --- a/wp-admin/includes/user.php +++ b/wp-admin/includes/user.php @@ -47,10 +47,10 @@ function edit_user( $user_id = 0 ) { $pass1 = ''; $pass2 = ''; if ( isset( $_POST['pass1'] ) ) { - $pass1 = $_POST['pass1']; + $pass1 = trim( $_POST['pass1'] ); } if ( isset( $_POST['pass2'] ) ) { - $pass2 = $_POST['pass2']; + $pass2 = trim( $_POST['pass2'] ); } if ( isset( $_POST['role'] ) && current_user_can( 'promote_users' ) && ( ! $user_id || current_user_can( 'promote_user', $user_id ) ) ) { diff --git a/wp-admin/js/user-profile.js b/wp-admin/js/user-profile.js index b73f2ab5c4..ef3e1afcc9 100644 --- a/wp-admin/js/user-profile.js +++ b/wp-admin/js/user-profile.js @@ -215,7 +215,7 @@ var pass1 = $('#pass1').val(), strength; $('#pass-strength-result').removeClass('short bad good strong empty'); - if ( ! pass1 ) { + if ( ! pass1 || '' === pass1.trim() ) { $( '#pass-strength-result' ).addClass( 'empty' ).html( ' ' ); return; } diff --git a/wp-admin/js/user-profile.min.js b/wp-admin/js/user-profile.min.js index 2cc326b577..5779cabb4b 100644 --- a/wp-admin/js/user-profile.min.js +++ b/wp-admin/js/user-profile.min.js @@ -1,2 +1,2 @@ /*! This file is auto-generated */ -!function(r){var a,t,n,i,o,d,l,p,c,u=!1,e=wp.i18n.__;function h(){"function"==typeof zxcvbn?(t.val()?m():(t.val(t.data("pw")),t.trigger("pwupdate")),v(),1!==parseInt(d.data("start-masked"),10)?t.attr("type","text"):d.trigger("click"),r("#pw-weak-text-label").text(e("Confirm use of weak password"))):setTimeout(h,50)}function f(s){d.attr({"aria-label":e(s?"Show password":"Hide password")}).find(".text").text(e(s?"Show":"Hide")).end().find(".dashicons").removeClass(s?"dashicons-hidden":"dashicons-visibility").addClass(s?"dashicons-visibility":"dashicons-hidden")}function w(){var s,e;a=r(".user-pass1-wrap, .user-pass-wrap"),r(".user-pass2-wrap").hide(),p=r("#submit, #wp-submit").on("click",function(){u=!1}),l=p.add(" #createusersub"),i=r(".pw-weak"),(o=i.find(".pw-checkbox")).change(function(){l.prop("disabled",!o.prop("checked"))}),(t=r("#pass1")).length?(c=t.val(),1===parseInt(t.data("reveal"),10)&&h(),t.on("input pwupdate",function(){t.val()!==c&&(c=t.val(),t.removeClass("short bad good strong"),v())})):t=r("#user_pass"),n=r("#pass2").on("input",function(){0]*>/gi,"");n[s].length&&-1===r.inArray(a,t)&&(t.push(a),r("