From 1eff14d093d541d9858f73ffca042de5a2bf3ea5 Mon Sep 17 00:00:00 2001 From: arno Date: Mon, 24 Aug 2009 00:00:46 +0200 Subject: [PATCH] do not allow empty passwords --- api.php | 6 ++++++ inc/db/anydb.php | 3 ++- inc/db/mysql.php | 3 +++ inc/html/admin.php | 1 + inc/html/install.php | 30 +++++++++++++++++++++++++----- inc/i10n/en/syp.php | 3 +++ inc/i10n/fr/syp.php | 5 +++++ js/admin.js | 12 ++++++++++++ 8 files changed, 57 insertions(+), 6 deletions(-) diff --git a/api.php b/api.php index ac49d76..e74f3b4 100644 --- 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); diff --git a/inc/db/anydb.php b/inc/db/anydb.php index 1094365..b63a264 100644 --- a/inc/db/anydb.php +++ b/inc/db/anydb.php @@ -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); diff --git a/inc/db/mysql.php b/inc/db/mysql.php index 8c07aa3..8383607 100644 --- a/inc/db/mysql.php +++ b/inc/db/mysql.php @@ -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';", diff --git a/inc/html/admin.php b/inc/html/admin.php index 7702b94..d6d876b 100644 --- a/inc/html/admin.php +++ b/inc/html/admin.php @@ -69,6 +69,7 @@ if (!$usrtblexists || !$itemstblexists) { UnconsistentError: "", DelSucces: "", UpdateSucces: "", + emptyPasswordError: "", userPasswordmatchError: "", changeSamePass: "", changePassBadPass: "", diff --git a/inc/html/install.php b/inc/html/install.php index d3def31..4b2d02c 100644 --- a/inc/html/install.php +++ b/inc/html/install.php @@ -10,6 +10,10 @@ <?php ptrans ('SYP wizard')?> @@ -192,7 +207,8 @@ 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) { @@ -207,11 +223,15 @@ par_success (trans ('Admin password initialized.')); } else { - print ('
+ print (' - - -
'); + '); + if ($empty_pass) { + print ('

' . trans('Password cannot be empty') . '

'); + } else { + print (''); + } + print ('
'); leave (); } } diff --git a/inc/i10n/en/syp.php b/inc/i10n/en/syp.php index 316158b..de65072 100644 --- a/inc/i10n/en/syp.php +++ b/inc/i10n/en/syp.php @@ -17,6 +17,9 @@ "SYP wizard" => "", + "Password cannot be empty" + => "", + "exist but is not a directory" => "", diff --git a/inc/i10n/fr/syp.php b/inc/i10n/fr/syp.php index 1cb3600..d4240b5 100644 --- a/inc/i10n/fr/syp.php +++ b/inc/i10n/fr/syp.php @@ -18,6 +18,11 @@ "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" diff --git a/js/admin.js b/js/admin.js index 85a28dd..36c7406 100644 --- a/js/admin.js +++ b/js/admin.js @@ -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({ -- 2.39.2