First version of "password strength" tester.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 25 Apr 2008 20:49:48 +0000 (22:49 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Fri, 25 Apr 2008 20:51:56 +0000 (22:51 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
templates/platal/motdepasse.tpl

index 390be6c..d5c368c 100644 (file)
 </p>
 <br />
 <form action="{$smarty.server.REQUEST_URI}" method="post" id="changepass">
+  {javascript name="jquery"}
+  <script type="text/javascript">//<![CDATA[
+  {literal}
+    function getType(char) {
+      if (char >= 'a' && char <= 'z') {
+        return 1;
+      } else if (char >= 'A' && char <= 'Z') {
+        return 2;
+      } else if (char >= '1' && char <= '2') {
+        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").width(prop + "%").css("background-color", ok ? "green" : "red");
+      if (ok) {
+        $(":submit").removeAttr("disabled");
+      } else {
+        $(":submit").attr("disabled", "disabled");
+      }
+    }
+    {/literal}
+  //]]></script>
   <table class="tinybicol" cellpadding="3" cellspacing="0"
     summary="Formulaire de mot de passe">
     <tr>
@@ -47,7 +95,7 @@
         Nouveau mot de passe&nbsp;:
       </td>
       <td>
-        <input type="password" size="10" maxlength="10" name="nouveau" />
+        <input type="password" size="10" maxlength="10" name="nouveau" onkeyup="checkPassword(this)" />
       </td>
     </tr>
     <tr>
       </td>
     </tr>
     <tr>
+      <td class="titre">
+        Sécurité
+      </td>
+      <td>
+        <div style="border: 1px solid white; width: 250px; height: 7px; background-color: #444">
+          <div id="passwords" style="height: 100%; background-color: red; width: 0px"></div>
+        </div>
+      </td>
+    </tr>
+    <tr>
       <td colspan="2" class="center">
-        <input type="submit" value="Changer" name="submitn" onclick="EnCryptedResponse(); return false;" />
+        <input type="submit" value="Changer" name="submitn" disabled="disabled"
+               onclick="EnCryptedResponse(); return false;" />
       </td>
     </tr>
   </table>