wp/wp-admin/js/password-strength-meter.js
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
--- a/wp/wp-admin/js/password-strength-meter.js	Mon Oct 14 18:06:33 2019 +0200
+++ b/wp/wp-admin/js/password-strength-meter.js	Mon Oct 14 18:28:13 2019 +0200
@@ -1,15 +1,33 @@
+/**
+ * @output wp-admin/js/password-strength-meter.js
+ */
+
 /* global zxcvbn */
 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.
+		 *
+		 * Compares first password to the password confirmation.
+		 *
+		 * @since 3.7.0
 		 *
-		 * @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
+		 * @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 +46,15 @@
 		},
 
 		/**
-		 * 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 +62,7 @@
 				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 +78,10 @@
 				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 +89,10 @@
 				}
 			}
 
-			// 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 +105,17 @@
 		}
 	};
 
-	// Back-compat.
-	passwordStrength = wp.passwordStrength.meter;
+	// Backward compatibility.
+
+	/**
+	 * Password strength meter function.
+	 *
+	 * @since 2.5.0
+	 * @deprecated 3.7.0 Use wp.passwordStrength.meter instead.
+	 *
+	 * @global
+	 *
+	 * @type {wp.passwordStrength.meter}
+	 */
+	window.passwordStrength = wp.passwordStrength.meter;
 })(jQuery);