Use Dropbox's zxcvbn library for our password meter.

The library was added in [25156].

props duck_.
see #21737.

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


git-svn-id: http://core.svn.wordpress.org/trunk@25136 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2013-08-28 16:09:10 +00:00
parent 1370cf9a7b
commit 09e92faa6c
7 changed files with 73 additions and 39 deletions

View File

@ -1,36 +1,6 @@
// Password strength meter
function passwordStrength(password1, username, password2) {
var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, mismatch = 5, symbolSize = 0, natLog, score;
// password 1 != password 2
if ( (password1 != password2) && password2.length > 0)
return mismatch
//password < 4
if ( password1.length < 4 )
return shortPass
//password1 == username
if ( password1.toLowerCase() == username.toLowerCase() )
return badPass;
if ( password1.match(/[0-9]/) )
symbolSize +=10;
if ( password1.match(/[a-z]/) )
symbolSize +=26;
if ( password1.match(/[A-Z]/) )
symbolSize +=26;
if ( password1.match(/[^a-zA-Z0-9]/) )
symbolSize +=31;
natLog = Math.log( Math.pow(symbolSize, password1.length) );
score = natLog / Math.LN2;
if (score < 40 )
return badPass
if (score < 56 )
return goodPass
return strongPass;
if (password1 != password2 && password2.length > 0)
return 5;
var result = zxcvbn( password1, [ username ] );
return result.score;
}

View File

@ -1 +1 @@
function passwordStrength(a,b,c){var d,e,f=1,g=2,h=3,i=4,j=5,k=0;return a!=c&&c.length>0?j:a.length<4?f:a.toLowerCase()==b.toLowerCase()?g:(a.match(/[0-9]/)&&(k+=10),a.match(/[a-z]/)&&(k+=26),a.match(/[A-Z]/)&&(k+=26),a.match(/[^a-zA-Z0-9]/)&&(k+=31),d=Math.log(Math.pow(k,a.length)),e=d/Math.LN2,40>e?g:56>e?h:i)}
function passwordStrength(a,b,c){if(a!=c&&c.length>0)return 5;var d=zxcvbn(a,[b]);return d.score}

View File

@ -0,0 +1,17 @@
(function() {
var async_load = function() {
var first, s;
s = document.createElement('script');
s.src = _zxcvbnSettings.src;
s.type = 'text/javascript';
s.async = true;
first = document.getElementsByTagName('script')[0];
return first.parentNode.insertBefore(s, first);
};
if (window.attachEvent != null) {
window.attachEvent('onload', async_load);
} else {
window.addEventListener('load', async_load, false);
}
}).call(this);

1
wp-includes/js/zxcvbn-async.min.js vendored Normal file
View File

@ -0,0 +1 @@
!function(){var a=function(){var a,b;return b=document.createElement("script"),b.src=_zxcvbnSettings.src,b.type="text/javascript",b.async=!0,a=document.getElementsByTagName("script")[0],a.parentNode.insertBefore(b,a)};null!=window.attachEvent?window.attachEvent("onload",a):window.addEventListener("load",a,!1)}.call(this);

File diff suppressed because one or more lines are too long

View File

@ -309,7 +309,12 @@ function wp_default_scripts( &$scripts ) {
'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ),
) );
$scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array('jquery'), false, 1 );
$scripts->add( 'zxcvbn-async', "/wp-includes/js/zxcvbn-async$suffix.js", array(), '1.0' );
did_action( 'init' ) && $scripts->localize( 'zxcvbn-async', '_zxcvbnSettings', array(
'src' => includes_url( '/js/zxcvbn.min.js' ),
) );
$scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array( 'jquery', 'zxcvbn-async' ), false, 1 );
did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
'empty' => __('Strength indicator'),
'short' => __('Very weak'),

View File

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