r70769 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70768‎ | r70769 | r70770 >
Date:16:17, 9 August 2010
Author:maxsem
Status:reverted
Tags:
Comment:
Fixes for password checker from r70520:
* Removed the upper bound for brute force complexity checks
* Score for repetitions is now linear and is subtracted from brute force score to avoid overpenalizing long passwords
* Disabled checks by default for now, since many people consider them overly intrusive
* Made OutputPage::addPasswordSecurity() include jQuery just in case it's not already included
* Documented a little
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/skins/common/password.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/password.js
@@ -5,20 +5,16 @@
66 * @todo Check for popular passwords and keyboard sequences (QWERTY, etc)
77 */
88
 9+// Estimates how hard it would be to pick the password using brute forece
910 function bruteForceComplexity( pwd ) {
10 - var score = 0;
 11+ var score = pwd.length * 5;
1112
12 - if ( pwd.length < 16 ) {
13 - score = pwd.length * 5;
14 - } else {
15 - score = 80;
16 - }
17 -
1813 var regexes = [
1914 /[a-z]/,
2015 /[A-Z]/,
2116 /[0-9]/,
22 - /[-_;:\.,'"`~!@#$%\^&\*\(\)\[\]\{\} ]/ ];
 17+ /[-_;:\.,'"`~!@#$%\^&\*\(\)\[\]\{\} ]/
 18+ ];
2319
2420 var charClasses = 0;
2521 for ( var i=0; i< regexes.length; i++ ) {
@@ -42,7 +38,8 @@
4339 return score;
4440 }
4541
46 -function repetitionScore( pwd ) {
 42+// Calculates a penalty to brute force score due to character repetition
 43+function repetitionAdjustment( pwd ) {
4744 var unique = '';
4845 for ( var i=0; i< pwd.length; i++ ) {
4946 if ( unique.indexOf( pwd[i] ) < 0 ) {
@@ -51,9 +48,10 @@
5249 }
5350 var ratio = pwd.length / unique.length - 0.4; // allow up to 40% repetition, reward for less, penalize for more
5451
55 - return 100 / ratio;
 52+ return ratio * 10;
5653 }
5754
 55+// Checks how many simple sequences ("abc", "321") are there in the password
5856 function sequenceScore( pwd ) {
5957 pwd = pwd.concat( '\0' );
6058 var score = 100, sequence = 1;
@@ -62,7 +60,7 @@
6361 sequence++;
6462 } else {
6563 if ( sequence > 2 ) {
66 - score -= Math.sqrt( sequence ) * 15;
 64+ score -= sequence * 7;
6765 }
6866 sequence = 1;
6967 }
@@ -89,23 +87,26 @@
9088 return;
9189 }
9290 if ( pwd.length > 100 ) pwd = pwd.slice( 0, 100 );
93 - var score = Math.min(
 91+ var scores = [
9492 bruteForceComplexity( pwd ),
95 - repetitionScore( pwd ),
 93+ repetitionAdjustment( pwd ),
9694 sequenceScore( pwd )
97 - );
 95+ ];
 96+
 97+ var score = Math.min( scores[0] - scores[1], scores[2] );
9898 var result = 'good';
9999 if ( score < 40 ) {
100100 result = 'bad';
101101 } else if ( score < 60 ) {
102102 result = 'mediocre';
103 - } else if ( score < 85 ) {
 103+ } else if ( score < 80 ) {
104104 result = 'acceptable';
105105 }
106106 var message = '<span class="mw-password-' + result + '">' + passwordSecurity.messages['password-strength-' + result]
107107 + '</span>';
108108 $( '#password-strength' ).html(
109109 passwordSecurity.messages['password-strength'].replace( '$1', message )
 110+ //+ scores
110111 );
111112 }
112113
Index: trunk/phase3/includes/OutputPage.php
@@ -1955,7 +1955,14 @@
19561956 }
19571957 }
19581958
 1959+ /**
 1960+ * Adds JS-based password security checker
 1961+ * @param $passwordId String ID of input box containing password
 1962+ * @param $retypeId String ID of input box containing retyped password
 1963+ * @return none
 1964+ */
19591965 public function addPasswordSecurity( $passwordId, $retypeId ) {
 1966+ $this->includeJQuery();
19601967 $data = array(
19611968 'password' => '#' . $passwordId,
19621969 'retype' => '#' . $retypeId,
Index: trunk/phase3/includes/DefaultSettings.php
@@ -5086,7 +5086,7 @@
50875087 /**
50885088 * Enabes or disables JavaScript-based suggestions of password strength
50895089 */
5090 -$wgLivePasswordStrengthChecks = true;
 5090+$wgLivePasswordStrengthChecks = false;
50915091
50925092 /**
50935093 * For really cool vim folding this needs to be at the end:

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70520JavaScript-based password complexity checker on account creation and password...maxsem19:16, 5 August 2010

Status & tagging log