]> dev.renevier.net Git - syp.git/commitdiff
do not allow empty passwords
authorarno <arenevier@fdn.fr>
Sun, 23 Aug 2009 22:00:46 +0000 (00:00 +0200)
committerarno <arenevier@fdn.fr>
Sun, 23 Aug 2009 22:00:46 +0000 (00:00 +0200)
api.php
inc/db/anydb.php
inc/db/mysql.php
inc/html/admin.php
inc/html/install.php
inc/i10n/en/syp.php
inc/i10n/fr/syp.php
js/admin.js

diff --git a/api.php b/api.php
index ac49d76665ca7cec11da77cad84d1b03c3bc3181..e74f3b46ff1e0d873f486053ae8f47f0aa157bbb 100644 (file)
--- a/api.php
+++ b/api.php
@@ -344,6 +344,9 @@ function main ($con) {
             try {
                 $con->setpwd ($user, $newpass);
             } catch (Exception $e) {
+                if ($e->getMessage () == anydbConnection::err_query) {
+                    error_request ();
+                }
                 error_server ();
             }
             setcookies ($user, $newpass);
@@ -364,6 +367,9 @@ function main ($con) {
             try {
                 $con->setpwd ($newuser_name, $newuser_password);
             } catch (Exception $e) {
+                if ($e->getMessage () == anydbConnection::err_query) {
+                    error_request ();
+                }
                 error_server ();
             }
             success_newuser ($newuser_name);
index 1094365eb42a6201d99bdd0e851427d096e60977..b63a26400208ceafbc79ee9e5af2f630a60f2495 100644 (file)
@@ -100,7 +100,8 @@ interface anydbConnection {
 
     /*
      * set password $pwd for user $usrname. If $usrname does not exist, create
-     * it
+     * it.
+     * throws an err_query error in case $pwd is null
      */
     public function setpwd($usrname, $pwd);
 
index 8c07aa3de81c304922b7376d6d266ef13b9ca2c8..83836074c05a219b4cc8b033d1b9afe6c5ec573a 100644 (file)
@@ -63,6 +63,9 @@ class mysqlConnection implements anydbConnection {
     }
 
     public function setpwd ($user_name, $pwd) {
+        if (strlen ($pwd) == 0) {
+            throw new Exception (anydbConnection::err_query);
+        }
         $usrname_escaped = mysql_real_escape_string ($user_name);
         if ($this->user_exists ($user_name)) {
             $query = sprintf ("UPDATE %susers SET pwd='%s' WHERE name like '%s';", 
index 7702b949b7408fd720eaf0f140b042af2e7e3fb1..d6d876b105aa570631c4e02cff7105d9ba60d569 100644 (file)
@@ -69,6 +69,7 @@ if (!$usrtblexists || !$itemstblexists) {
             UnconsistentError: "<?php ptrans('Server reply was inconsistent.')?>",
             DelSucces: "<?php ptrans('Removal took place correctly.')?>",
             UpdateSucces: "<?php ptrans('Save took place correctly.')?>",
+            emptyPasswordError: "<?php ptrans('Password cannot be empty')?>",
             userPasswordmatchError: "<?php ptrans('Passwords do not match.')?>",
             changeSamePass: "<?php ptrans('New password is the same as old password.')?>",
             changePassBadPass: "<?php ptrans('Bad password.')?>",
index d3def31fe5b96dbb7273298cb98f7ac777e2e65c..4b2d02cb3673dca4cc1a1a53d096015f807cce6b 100644 (file)
       <link rel="stylesheet" href="./media/install.css" type="text/css" >
       <title><?php ptrans ('SYP wizard')?></title>
       <script type="text/javascript">
+      var sypStrings = {
+            emptyPasswordError: "<?php ptrans('Password cannot be empty')?>"
+      };
+
       function init () {
         if (document.getElementById('db_host')) { 
             document.getElementById('db_host').focus();
             document.getElementById('admin_pass').select();
         }
       }
+
+      function checkpwd () {
+          var pass = document.getElementById('admin_pass').value;
+          if (!pass) {
+              document.getElementById('empty_pass_error').innerHTML = sypStrings.emptyPasswordError;
+              document.getElementById('empty_pass_error').style.display = "block";
+              document.getElementById('admin_pass').focus();
+              return false;
+          }
+          return true;
+      }
       </script>
 </head>
 <body onload="init()">
     if ($users_table_exists) {
         par_success (trans ('Found user table.'));
     } else {
-        if (isset($_POST ["admin_pass"])) {
+        $empty_pass = (isset ($_POST ["admin_pass"]) && (strlen ($_POST ["admin_pass"]) == 0));
+        if ($_POST ["admin_pass"]) {
             try {
                 $connection->create_users_table (true);
             } catch (Exception $e) {
             par_success (trans ('Admin password initialized.'));
 
         } else {
-            print ('<form class="center" method="post" action="">
+            print ('<form class="center" method="post" action="" onsubmit="return checkpwd()">
                     <label for="admin_pass">' . trans ("choose admin password") . '</label>
-                    <input id="admin_pass" name="admin_pass" type="password">
-                    <input type="submit">
-                 </form>');
+                    <input id="admin_pass" name="admin_pass" type="password">');
+            if ($empty_pass) {
+                print ('<p class="error" id="empty_pass_error">' . trans('Password cannot be empty') . '</p>');
+            } else {
+                print ('<p class="error" style="display: none" id="empty_pass_error"></p>');
+            }
+            print ('<br><input type="submit"></form>');
             leave ();
         }
     }
index 316158b9d60a1953e63fd6b49bf6f398c025d97d..de65072d0325ea8171070039e2312baca50715db 100644 (file)
@@ -17,6 +17,9 @@
         "SYP wizard"
           => "",
 
+        "Password cannot be empty"
+          => "",
+
         "exist but is not a directory"
           => "",
 
index 1cb36008c66be9e2640154dcdc72164bf25cca62..d4240b5a0e0266af0d4888d54ab1c9d029b12cd3 100644 (file)
         "Assistant d'installation de SYP"
           ,
 
+        "Password cannot be empty"
+          =>
+        "Le mot de passe ne peut pas ĂȘtre vide"
+          ,
+
         "exist but is not a directory"
           =>
         "existe mais n'est pas un rĂ©pertoire"
index 85a28ddca09ee94712d9ba3e547bd01a6745a30f..36c74069397145bde8909b5116ea1d529a62c6fc 100644 (file)
@@ -923,6 +923,12 @@ var userMgr = {
             return;
         }
 
+        if (!newpass) {
+            this.commError(SypStrings.emptyPasswordError);
+            $("#pass_new").focus().select();
+            return;
+        }
+
         var curpass = $("#pass_current").val();
         if (newpass == curpass) {
             this.commError(SypStrings.changeSamePass);
@@ -1008,6 +1014,12 @@ var userMgr = {
             return;
         }
 
+        if (!newuser_pass) {
+            this.commError(SypStrings.emptyPasswordError);
+            $("#pass_new").focus().select();
+            return;
+        }
+
         this.commError("");
 
         AjaxMgr.add({