diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-admin/js/password-strength-meter.js --- a/wp/wp-admin/js/password-strength-meter.js Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-admin/js/password-strength-meter.js Tue Dec 15 13:49:49 2020 +0100 @@ -6,6 +6,8 @@ window.wp = window.wp || {}; (function($){ + var __ = wp.i18n.__, + sprintf = wp.i18n.sprintf; /** * Contains functions to determine the password strength. @@ -22,16 +24,16 @@ * * @since 3.7.0 * - * @param {string} password1 The subject password. - * @param {Array} blacklist An array of words that will lower the entropy of - * the password. - * @param {string} password2 The password confirmation. + * @param {string} password1 The subject password. + * @param {Array} disallowedList An array of words that will lower the entropy of + * the password. + * @param {string} password2 The password confirmation. * - * @returns {number} The password strength score. + * @return {number} The password strength score. */ - meter : function( password1, blacklist, password2 ) { - if ( ! $.isArray( blacklist ) ) - blacklist = [ blacklist.toString() ]; + meter : function( password1, disallowedList, password2 ) { + if ( ! $.isArray( disallowedList ) ) + disallowedList = [ disallowedList.toString() ]; if (password1 != password2 && password2 && password2.length > 0) return 5; @@ -41,7 +43,7 @@ return -1; } - var result = zxcvbn( password1, blacklist ); + var result = zxcvbn( password1, disallowedList ); return result.score; }, @@ -49,20 +51,46 @@ * Builds an array of words that should be penalized. * * Certain words need to be penalized because it would lower the entropy of a - * password if they were used. The blacklist is based on user input fields such + * password if they were used. The disallowedList is based on user input fields such * as username, first name, email etc. * * @since 3.7.0 + * @deprecated 5.5.0 Use {@see 'userInputDisallowedList()'} instead. * - * @returns {string[]} The array of words to be blacklisted. + * @return {string[]} The array of words to be disallowed. */ userInputBlacklist : function() { + window.console.log( + sprintf( + /* translators: 1: Deprecated function name, 2: Version number, 3: Alternative function name. */ + __( '%1$s is deprecated since version %2$s! Use %3$s instead. Please consider writing more inclusive code.' ), + 'wp.passwordStrength.userInputBlacklist()', + '5.5.0', + 'wp.passwordStrength.userInputDisallowedList()' + ) + ); + + return wp.passwordStrength.userInputDisallowedList(); + }, + + /** + * Builds an array of words that should be penalized. + * + * Certain words need to be penalized because it would lower the entropy of a + * password if they were used. The disallowed list is based on user input fields such + * as username, first name, email etc. + * + * @since 5.5.0 + * + * @return {string[]} The array of words to be disallowed. + */ + userInputDisallowedList : function() { var i, userInputFieldsLength, rawValuesLength, currentField, rawValues = [], - blacklist = [], + disallowedList = [], userInputFields = [ 'user_login', 'first_name', 'last_name', 'nickname', 'display_name', 'email', 'url', 'description', 'weblog_title', 'admin_email' ]; - // Collect all the strings we want to blacklist. + // Collect all the strings we want to disallow. rawValues.push( document.title ); rawValues.push( document.URL ); @@ -85,7 +113,7 @@ rawValuesLength = rawValues.length; for ( i = 0; i < rawValuesLength; i++ ) { if ( rawValues[ i ] ) { - blacklist = blacklist.concat( rawValues[ i ].replace( /\W/g, ' ' ).split( ' ' ) ); + disallowedList = disallowedList.concat( rawValues[ i ].replace( /\W/g, ' ' ).split( ' ' ) ); } } @@ -93,15 +121,15 @@ * Remove empty values, short words and duplicates. Short words are likely to * cause many false positives. */ - blacklist = $.grep( blacklist, function( value, key ) { + disallowedList = $.grep( disallowedList, function( value, key ) { if ( '' === value || 4 > value.length ) { return false; } - return $.inArray( value, blacklist ) === key; + return $.inArray( value, disallowedList ) === key; }); - return blacklist; + return disallowedList; } };