+
+/***************************************************************************
+ * 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, okLabel) {
+ var prev = 0;
+ var prop = 0;
+ var pass = box.value;
+ var types = Array(0, 0, 0, 0, 0);
+ var firstType = true;
+ for (i = 0 ; i < pass.length ; ++i) {
+ type = getType(pass.charAt(i));
+ if (prev != 0 && prev != type) {
+ prop += 5;
+ }
+ prop += i;
+ if (types[type] == 0 && !firstType) {
+ prop += 15;
+ } else {
+ firstType = false;
+ }
+ types[type]++;
+ prev = type;
+ }
+ if (pass.length < 6) {
+ prop *= 0.75;
+ }
+ if (prop > 100) {
+ prop = 100;
+ } else if (prop < 0) {
+ prop = 0;
+ }
+ if (prop >= 60) {
+ color = "#4f4";
+ bgcolor = "#050";
+ ok = true;
+ } else if (prop >= 40) {
+ color = "#ff4";
+ bgcolor = "#750";
+ ok = true;
+ } else {
+ color = "#f20";
+ bgcolor = "#700";
+ ok = false;
+ }
+ $("#passwords_measure")
+ .stop()
+ .animate({ width: prop + "%",
+ backgroundColor: color
+ }, 750)
+ .parent().stop()
+ .animate({ backgroundColor: bgcolor }, 750);
+ var submitButton = $(":submit[@name='" + passwordprompt_submit + "']");
+ if (ok && pass.length >= 6) {
+ submitButton.attr("value", okLabel);
+ submitButton.removeAttr("disabled");
+ } else {
+ submitButton.attr("value", "Mot de passe trop faible");
+ submitButton.attr("disabled", "disabled");
+ }
+}
+
+// }}}
+
+