2 window.wp = window.wp || {};
6 wp.passwordStrength = {
8 * Determine the strength of a given password
10 * @param string password1 The password
11 * @param array blacklist An array of words that will lower the entropy of the password
12 * @param string password2 The confirmed password
14 meter : function( password1, blacklist, password2 ) {
15 if ( ! $.isArray( blacklist ) )
16 blacklist = [ blacklist.toString() ];
18 if (password1 != password2 && password2 && password2.length > 0)
21 if ( 'undefined' === typeof window.zxcvbn ) {
22 // Password strength unknown.
26 var result = zxcvbn( password1, blacklist );
31 * Builds an array of data that should be penalized, because it would lower the entropy of a password if it were used
33 * @return array The array of data to be blacklisted
35 userInputBlacklist : function() {
36 var i, userInputFieldsLength, rawValuesLength, currentField,
39 userInputFields = [ 'user_login', 'first_name', 'last_name', 'nickname', 'display_name', 'email', 'url', 'description', 'weblog_title', 'admin_email' ];
41 // Collect all the strings we want to blacklist
42 rawValues.push( document.title );
43 rawValues.push( document.URL );
45 userInputFieldsLength = userInputFields.length;
46 for ( i = 0; i < userInputFieldsLength; i++ ) {
47 currentField = $( '#' + userInputFields[ i ] );
49 if ( 0 === currentField.length ) {
53 rawValues.push( currentField[0].defaultValue );
54 rawValues.push( currentField.val() );
57 // Strip out non-alphanumeric characters and convert each word to an individual entry
58 rawValuesLength = rawValues.length;
59 for ( i = 0; i < rawValuesLength; i++ ) {
60 if ( rawValues[ i ] ) {
61 blacklist = blacklist.concat( rawValues[ i ].replace( /\W/g, ' ' ).split( ' ' ) );
65 // Remove empty values, short words, and duplicates. Short words are likely to cause many false positives.
66 blacklist = $.grep( blacklist, function( value, key ) {
67 if ( '' === value || 4 > value.length ) {
71 return $.inArray( value, blacklist ) === key;
79 passwordStrength = wp.passwordStrength.meter;