Docs: Improve JSDoc for password-strength-meter.js.

Props herregroen, carolinegeven, ireneyoast, jjcomack.
Fixes #43066.

Built from https://develop.svn.wordpress.org/trunk@42528


git-svn-id: http://core.svn.wordpress.org/trunk@42357 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
atimmer 2018-01-18 13:39:33 +00:00
parent 44c89cac5a
commit d268976255
2 changed files with 49 additions and 11 deletions

View File

@ -3,13 +3,28 @@ window.wp = window.wp || {};
var passwordStrength;
(function($){
/**
* Contains functions to determine the password strength.
*
* @since 3.7.0
*
* @namespace
*/
wp.passwordStrength = {
/**
* Determine the strength of a given password
* Determines the strength of a given password.
*
* @param string password1 The password
* @param array blacklist An array of words that will lower the entropy of the password
* @param string password2 The confirmed password
* Compares first password to the password confirmation.
*
* @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.
*
* @returns {number} The password strength score.
*/
meter : function( password1, blacklist, password2 ) {
if ( ! $.isArray( blacklist ) )
@ -28,9 +43,15 @@ var passwordStrength;
},
/**
* Builds an array of data that should be penalized, because it would lower the entropy of a password if it were used
* Builds an array of words that should be penalized.
*
* @return array The array of data to be blacklisted
* 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
* as username, first name, email etc.
*
* @since 3.7.0
*
* @returns {string[]} The array of words to be blacklisted.
*/
userInputBlacklist : function() {
var i, userInputFieldsLength, rawValuesLength, currentField,
@ -38,7 +59,7 @@ var passwordStrength;
blacklist = [],
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 blacklist.
rawValues.push( document.title );
rawValues.push( document.URL );
@ -54,7 +75,10 @@ var passwordStrength;
rawValues.push( currentField.val() );
}
// Strip out non-alphanumeric characters and convert each word to an individual entry
/*
* Strip out non-alphanumeric characters and convert each word to an
* individual entry.
*/
rawValuesLength = rawValues.length;
for ( i = 0; i < rawValuesLength; i++ ) {
if ( rawValues[ i ] ) {
@ -62,7 +86,10 @@ var passwordStrength;
}
}
// Remove empty values, short words, and duplicates. Short words are likely to cause many false positives.
/*
* Remove empty values, short words and duplicates. Short words are likely to
* cause many false positives.
*/
blacklist = $.grep( blacklist, function( value, key ) {
if ( '' === value || 4 > value.length ) {
return false;
@ -75,6 +102,17 @@ var passwordStrength;
}
};
// Back-compat.
// Backward compatibility.
/**
* Password strength meter function.
*
* @since 2.5.0
* @deprecated 3.7.0 Use wp.passwordStrength.meter instead.
*
* @global
*
* @type {wp.passwordStrength.meter}
*/
passwordStrength = wp.passwordStrength.meter;
})(jQuery);

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.0-alpha-42527';
$wp_version = '5.0-alpha-42528';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.