From 7143ad2b35b4340435d83537504987851b9b8600 Mon Sep 17 00:00:00 2001
From: Florent Bruneau
Date: Sat, 3 May 2008 23:34:22 +0200
Subject: [PATCH] Make password checker easily pluggable to any password change
prompt.
Signed-off-by: Florent Bruneau
---
htdocs/javascript/xorg.js | 61 ++++++++++++++++++++++++++++++++++++++--
plugins/compiler.checkpasswd.php | 44 +++++++++++++++++++++++++++++
templates/platal/motdepasse.tpl | 54 ++---------------------------------
3 files changed, 104 insertions(+), 55 deletions(-)
create mode 100644 plugins/compiler.checkpasswd.php
diff --git a/htdocs/javascript/xorg.js b/htdocs/javascript/xorg.js
index 0e7f8e6..7cb2fe3 100644
--- a/htdocs/javascript/xorg.js
+++ b/htdocs/javascript/xorg.js
@@ -32,7 +32,7 @@ function getNow() {
if (yr<1000) yr += 1900;
hr = dt.getHours();
mi = dt.getMinutes();
-
+
time = (mi < 10) ? hr +':0'+mi : hr+':'+mi;
days = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
months = ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet',
@@ -66,7 +66,7 @@ function addSearchEngine()
try {
window.external.AddSearchProvider(searchURI);
} catch(e) {
- alert("Impossible d'installer la barre de recherche");
+ alert("Impossible d'installer la barre de recherche");
}
}
}
@@ -89,7 +89,7 @@ function attachEvent(obj, evt, f, useCapture) {
return true;
} else if (obj.attachEvent) {
return obj.attachEvent("on"+evt, f);
- }
+ }
return false;
}
@@ -280,6 +280,61 @@ function auto_links_nodes(nodes) {
// }}}
+
+/***************************************************************************
+ * Password check
+ */
+
+// {{{ function checkPassword
+
+function getType(char) {
+ if (char >= 'a' && char <= 'z') {
+ return 1;
+ } else if (char >= 'A' && char <= 'Z') {
+ return 2;
+ }Â else if (char >= '0' && char <= '9') {
+ return 3;
+ } else {
+ return 4;
+ }
+}
+
+function checkPassword(box) {
+ var prev = 0;
+ var prop = 0;
+ var pass = box.value;
+ var types = Array(0, 0, 0, 0, 0);
+ for (i = 0 ; i < pass.length ; ++i) {
+ type = getType(pass.charAt(i));
+ if (prev != 0 && prev != type) {
+ prop += 5;
+ }
+ if (i >= 5) {
+ prop += 5;
+ }
+ if (types[type] == 0) {
+ prop += 10;
+ }
+ types[type]++;
+ prev = type;
+ }
+ if (prop > 100) {
+ prop = 100;
+ } else if (prop < 0) {
+ prop = 0;
+ }
+ ok = (prop >= 60);
+ $("#passwords_measure").width(prop + "%").css("background-color", ok ? "green" : "red");
+ if (ok) {
+ $(":submit").removeAttr("disabled");
+ } else {
+ $(":submit").attr("disabled", "disabled");
+ }
+}
+
+// }}}
+
+
/***************************************************************************
* The real OnLoad
*/
diff --git a/plugins/compiler.checkpasswd.php b/plugins/compiler.checkpasswd.php
new file mode 100644
index 0000000..dbfbc71
--- /dev/null
+++ b/plugins/compiler.checkpasswd.php
@@ -0,0 +1,44 @@
+_parse_attrs($tag_attrs));
+ if (!isset($width)) {
+ $width = '250px';
+ }
+ if (!isset($id)) {
+ $id = "newpassword";
+ }
+
+ return '?>
+
+
diff --git a/templates/platal/motdepasse.tpl b/templates/platal/motdepasse.tpl
index bbd48c0..91cb319 100644
--- a/templates/platal/motdepasse.tpl
+++ b/templates/platal/motdepasse.tpl
@@ -35,54 +35,6 @@