Docs: Improve JSDoc for `password-strength-meter.js`.
Props herregroen, carolinegeven, ireneyoast, jjcomack. Fixes #43066. git-svn-id: https://develop.svn.wordpress.org/trunk@42528 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2cb36cab72
commit
33cd11ecb6
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue