Tentative d'indication de la force des password. A débugger

Màj de jquery
Début d'intégration de la nouvelle structure de mail dans m_mail
This commit is contained in:
Alan Garcia 2011-06-04 13:46:33 +00:00
parent 3eb248a80b
commit 656b65fd9e
8 changed files with 217 additions and 73 deletions

3
.gitattributes vendored
View File

@ -200,6 +200,7 @@ bureau/admin/images/orig/plus.png -text
bureau/admin/images/orig/quota.png -text bureau/admin/images/orig/quota.png -text
bureau/admin/images/orig/stat.png -text bureau/admin/images/orig/stat.png -text
bureau/admin/images/password.png -text bureau/admin/images/password.png -text
bureau/admin/images/passwordstrength.jpg -text
bureau/admin/images/plus.png -text bureau/admin/images/plus.png -text
bureau/admin/images/quota.png -text bureau/admin/images/quota.png -text
bureau/admin/images/stat.png -text bureau/admin/images/stat.png -text
@ -227,6 +228,7 @@ bureau/admin/js/jquery_ui/js/jquery-ui-1.8.10.custom.min.js -text
bureau/admin/js/jquery_ui/js/jquery.ui.datepicker-de.js -text bureau/admin/js/jquery_ui/js/jquery.ui.datepicker-de.js -text
bureau/admin/js/jquery_ui/js/jquery.ui.datepicker-es.js -text bureau/admin/js/jquery_ui/js/jquery.ui.datepicker-es.js -text
bureau/admin/js/jquery_ui/js/jquery.ui.datepicker-fr.js -text bureau/admin/js/jquery_ui/js/jquery.ui.datepicker-fr.js -text
bureau/admin/js/passwordStrengthMeter.js -text
bureau/admin/js/prototype.js -text bureau/admin/js/prototype.js -text
bureau/admin/js/rico.js -text bureau/admin/js/rico.js -text
bureau/admin/js/wz_dragdrop.js -text bureau/admin/js/wz_dragdrop.js -text
@ -296,6 +298,7 @@ bureau/admin/sta2_doedit_raw.php -text
bureau/admin/sta2_edit_raw.php -text bureau/admin/sta2_edit_raw.php -text
bureau/admin/sta2_list.php -text bureau/admin/sta2_list.php -text
bureau/admin/stats_members.php -text bureau/admin/stats_members.php -text
bureau/admin/styles/passwordStrengthMeter.css -text
bureau/admin/styles/style.css -text bureau/admin/styles/style.css -text
bureau/admin/template.php -text bureau/admin/template.php -text
bureau/admin/trash_dateselect.php -text bureau/admin/trash_dateselect.php -text

View File

@ -35,6 +35,7 @@ if (!$charset) $charset="iso-8859-1";
<head> <head>
<title>Bureau</title> <title>Bureau</title>
<link rel="stylesheet" href="styles/style.css" type="text/css" /> <link rel="stylesheet" href="styles/style.css" type="text/css" />
<link rel="stylesheet" href="styles/passwordStrengthMeter.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" /> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
<script type="text/javascript" src="js/alternc.js"></script> <script type="text/javascript" src="js/alternc.js"></script>
<script type="text/javascript" src="js/wz_dragdrop.js"></script> <script type="text/javascript" src="js/wz_dragdrop.js"></script>
@ -46,6 +47,7 @@ if (file_exists($lang_date_picker))
echo "<script src=\"$lang_date_picker\" type=\"text/javascript\"></script>"; echo "<script src=\"$lang_date_picker\" type=\"text/javascript\"></script>";
?> ?>
<link href="js/jquery_ui/css/smoothness/jquery-ui-1.8.10.custom.css" rel="stylesheet" type="text/css" /> <link href="js/jquery_ui/css/smoothness/jquery-ui-1.8.10.custom.css" rel="stylesheet" type="text/css" />
<script src="js/passwordStrengthMeter.js" type="text/javascript"></script>
</head> </head>
<body> <body>
<? <?

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,132 @@
/* Intelligent Web NameSpace */
var IW = IW || {};
/**
* Password validator logic
*/
(function(IW) {
var secondsInADay = 86400;
function PasswordValidator() {
}
/**
* How long a password can be expected to last
*/
PasswordValidator.prototype.passwordLifeTimeInDays = 365;
/**
* An estimate of how many attempts could be made per second to guess a password
*/
PasswordValidator.prototype.passwordAttemptsPerSecond = 500;
/**
* An array of regular expressions to match against the password. Each is associated
* with the number of unique characters that each expression can match.
* @param password
*/
PasswordValidator.prototype.expressions = [
{
regex : /[A-Z]+/,
uniqueChars : 26
},
{
regex : /[a-z]+/,
uniqueChars : 26
},
{
regex : /[0-9]+/,
uniqueChars : 10
},
{
regex : /[!\?.;,\\@$£#*()%~<>{}\[\]]+/,
uniqueChars : 17
}
];
/**
* Checks the supplied password
* @param {String} password
* @return The predicted lifetime of the password, as a percentage of the defined password lifetime.
*/
PasswordValidator.prototype.checkPassword = function(password) {
if (password == null) password="0"
var
expressions = this.expressions,
i,
l = expressions.length,
expression,
possibilitiesPerLetterInPassword = 0;
for (i = 0; i < l; i++) {
expression = expressions[i];
if (expression.regex.exec(password)) {
possibilitiesPerLetterInPassword += expression.uniqueChars;
}
}
var
totalCombinations = Math.pow(possibilitiesPerLetterInPassword, password.length),
// how long, on average, it would take to crack this (@ 200 attempts per second)
crackTime = ((totalCombinations / this.passwordAttemptsPerSecond) / 2) / secondsInADay,
// how close is the time to the projected time?
percentage = crackTime / this.passwordLifeTimeInDays;
return Math.min(Math.max(password.length * 5, percentage * 100), 100);
};
IW.PasswordValidator = new PasswordValidator();
})(IW);
/**
* jQuery plugin which allows you to add password validation to any
* form element.
*/
(function(IW, jQuery) {
function updatePassword() {
var
percentage = IW.PasswordValidator.checkPassword(this.val()),
progressBar = this.parent().find(".passwordStrengthBar div");
progressBar
.removeClass("strong medium weak useless")
.stop()
.animate({"width": percentage + "%"});
if (percentage > 90) {
progressBar.addClass("strong");
} else if (percentage > 50) {
progressBar.addClass("medium")
} else if (percentage > 10) {
progressBar.addClass("weak");
} else {
progressBar.addClass("useless");
}
}
jQuery.fn.passwordValidate = function() {
this
.bind('keyup', jQuery.proxy(updatePassword, this))
.after("<div class='passwordStrengthBar'>" +
"<div></div>" +
"</div>");
updatePassword.apply(this);
return this; // for chaining
}
})(IW, jQuery);
/* Have all the password elements on the page validate */
jQuery("input[type='password']").passwordValidate();

View File

@ -0,0 +1,9 @@
.style1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-size: 12px;
}
.inbox { width:200px;border:solid 1px gray; }
.graybar { width:200px; background:#dddddd; height:3px; float:left; }
.colorbar {margin-top:-3px;width:1px;background-image:url(images/passwordstrength.jpg);height:3px; float:left;}
.percent {margin-top:0px;float:left;}
.result {color:green; font-family:Tahoma;font-size:11px;}

View File

@ -209,7 +209,7 @@ class m_mail {
function available($mail) { function available($mail) {
global $err,$db,$cuid; global $err,$db,$cuid;
$err->log("mail","available",$mail); $err->log("mail","available",$mail);
$db->query("SELECT mail FROM mail_domain WHERE mail='$mail';"); $db->query("SELECT address FROM address WHERE address='$mail';");
if ($db->next_record()) { if ($db->next_record()) {
return false; return false;
} else { } else {
@ -258,21 +258,17 @@ class m_mail {
* @param string $pass New password * @param string $pass New password
* @return boolean TRUE if the password has been changed, FALSE if an error occurred. * @return boolean TRUE if the password has been changed, FALSE if an error occurred.
*/ */
function change_password($mail,$pass) { function change_password($mail,$pass) { // NEW OK
global $err,$db,$cuid; global $err,$db,$cuid;
$err->log("mail","change_password",$mail); $err->log("mail","change_password",$mail);
$t=explode("@",$mail); $t=explode("@",$mail);
$email=$t[0]; $email=$t[0];
$dom=$t[1]; $dom=$t[1];
$db->query("SELECT mail,alias,pop FROM mail_domain WHERE mail='$mail' AND uid='$cuid';"); $db->query("SELECT address FROM address WHERE address='$mail' AND uid='$cuid';");
if (!$db->next_record()) { if (!$db->next_record()) {
$err->raise("mail",3,$mail); $err->raise("mail",3,$mail);
return false; return false;
} }
if (!$db->f("pop")) {
$err->raise("mail",15);
return false;
}
// Check this password against the password policy using common API : // Check this password against the password policy using common API :
if (is_callable(array($admin,"checkPolicy"))) { if (is_callable(array($admin,"checkPolicy"))) {
if (!$admin->checkPolicy("pop",$email."@".$dom,$pass)) { if (!$admin->checkPolicy("pop",$email."@".$dom,$pass)) {
@ -622,12 +618,12 @@ class m_mail {
* @return boolean TRUE si le compte pop a bien été modifié, FALSE si une erreur s'est produite. * @return boolean TRUE si le compte pop a bien été modifié, FALSE si une erreur s'est produite.
* @access private * @access private
*/ */
function _updatepop($mail,$dom,$pass) { function _updatepop($mail,$dom,$pass) { // NEW OK
global $err,$cuid,$db; global $err,$cuid,$db;
$err->log("mail","_updatepop",$mail."@".$dom); $err->log("mail","_updatepop",$mail."@".$dom);
$m=substr($mail,0,1); $m=substr($mail,0,1);
$gecos=$mail; $gecos=$mail;
$db->query("UPDATE mail_users SET password='"._md5cr($pass)."' WHERE ( alias='". $mail."_".$dom."' OR alias='". $mail."@".$dom."' ) AND uid='$cuid';"); $db->query("UPDATE address SET password='"._md5cr($pass)."' WHERE address='". $mail."@".$dom."' AND uid='$cuid';");
return true; return true;
} }