1 window.wp = window.wp || {};
5 wp.passwordStrength = {
7 * Determine the strength of a given password
9 * @param string password1 The password
10 * @param array blacklist An array of words that will lower the entropy of the password
11 * @param string password2 The confirmed password
13 meter : function( password1, blacklist, password2 ) {
14 if ( ! $.isArray( blacklist ) )
15 blacklist = [ blacklist.toString() ];
17 if (password1 != password2 && password2 && password2.length > 0)
20 var result = zxcvbn( password1, blacklist );
25 * Builds an array of data that should be penalized, because it would lower the entropy of a password if it were used
27 * @return array The array of data to be blacklisted
29 userInputBlacklist : function() {
30 var i, userInputFieldsLength, rawValuesLength, currentField,
33 userInputFields = [ 'user_login', 'first_name', 'last_name', 'nickname', 'display_name', 'email', 'url', 'description', 'weblog_title', 'admin_email' ];
35 // Collect all the strings we want to blacklist
36 rawValues.push( document.title );
37 rawValues.push( document.URL );
39 userInputFieldsLength = userInputFields.length;
40 for ( i = 0; i < userInputFieldsLength; i++ ) {
41 currentField = $( '#' + userInputFields[ i ] );
43 if ( 0 == currentField.length ) {
47 rawValues.push( currentField[0].defaultValue );
48 rawValues.push( currentField.val() );
51 // Strip out non-alphanumeric characters and convert each word to an individual entry
52 rawValuesLength = rawValues.length;
53 for ( i = 0; i < rawValuesLength; i++ ) {
54 if ( rawValues[ i ] ) {
55 blacklist = blacklist.concat( rawValues[ i ].replace( /\W/g, ' ' ).split( ' ' ) );
59 // Remove empty values, short words, and duplicates. Short words are likely to cause many false positives.
60 blacklist = $.grep( blacklist, function( value, key ) {
61 if ( '' == value || 4 > value.length ) {
65 return $.inArray( value, blacklist ) === key;
72 // Backwards compatibility.
73 passwordStrength = wp.passwordStrength.meter;