From f68122272dcca8694ccac70578b0fc35d3d70e06 Mon Sep 17 00:00:00 2001 From: tbrehm Date: Mon, 23 Mar 2009 20:31:48 +0000 Subject: [PATCH] Changed default encryption method for ispconfig controlpanel users from md5 to crypt-md5. --- interface/web/admin/form/users.tform.php | 1 + interface/web/client/form/client.tform.php | 2 +- interface/web/login/index.php | 27 +- interface/web/login/lib/lang/en.lng | 31 +- interface/web/login/lib/lang/es.lng | 26 +- interface/web/login/lib/lang/fr.lng | 26 +- interface/web/login/lib/lang/it.lng | 26 +- interface/web/login/lib/lang/nl.lng | 26 +- interface/web/login/lib/lang/se.lng | 26 +- interface/web/login/password_reset.php | 164 +++++----- .../web/tools/form/user_settings.tform.php | 285 +++++++++--------- 11 files changed, 342 insertions(+), 298 deletions(-) diff --git a/interface/web/admin/form/users.tform.php b/interface/web/admin/form/users.tform.php index 2466b23d0..1edbb0cc4 100644 --- a/interface/web/admin/form/users.tform.php +++ b/interface/web/admin/form/users.tform.php @@ -158,6 +158,7 @@ $form['tabs']['users'] = array ( 'passwort' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'PASSWORD', + 'encryption'=> 'CRYPT', 'regex' => '', 'errmsg' => '', 'default' => '', diff --git a/interface/web/client/form/client.tform.php b/interface/web/client/form/client.tform.php index 7497fdaed..288e8939a 100644 --- a/interface/web/client/form/client.tform.php +++ b/interface/web/client/form/client.tform.php @@ -119,7 +119,7 @@ $form["tabs"]['address'] = array ( 'password' => array ( 'datatype' => 'VARCHAR', 'formtype' => 'PASSWORD', - 'encryption'=> 'MD5', + 'encryption'=> 'CRYPT', 'default' => '', 'value' => '', 'separator' => '', diff --git a/interface/web/login/index.php b/interface/web/login/index.php index 36a3c3a1f..77fdf493e 100644 --- a/interface/web/login/index.php +++ b/interface/web/login/index.php @@ -58,8 +58,8 @@ class login_index { if(count($_POST) > 0) { //** Check variables - if(!preg_match("/^[\w\.\-\_]{1,64}$/", $_POST['username'])) $error = 'Username contains unallowed characters or is longer then 64 characters.'; - if(!preg_match("/^.{1,64}$/i", $_POST['passwort'])) $error = 'The password length is > 64 characters.'; + if(!preg_match("/^[\w\.\-\_]{1,64}$/", $_POST['username'])) $error = $app->lng('user_regex_error'); + if(!preg_match("/^.{1,64}$/i", $_POST['passwort'])) $error = $app->lng('pw_error_length'); //** iporting variables $ip = $app->db->quote(ip2long($_SERVER['REMOTE_ADDR'])); @@ -105,10 +105,29 @@ class login_index { } else { if ($loginAs){ $sql = "SELECT * FROM sys_user WHERE USERNAME = '$username' and PASSWORT = '". $passwort. "'"; + $user = $app->db->queryOneRecord($sql); } else { - $sql = "SELECT * FROM sys_user WHERE USERNAME = '$username' and ( PASSWORT = '".md5($passwort)."' or PASSWORT = password('$passwort') )"; + $sql = "SELECT * FROM sys_user WHERE USERNAME = '$username'"; + $user = $app->db->queryOneRecord($sql); + if($user && $user['active'] == 1) { + $saved_password = stripslashes($user['passwort']); + if(substr($saved_password,0,3) == '$1$') { + //* The password is crypt-md5 encrypted + $salt = '$1$'.substr($saved_password,3,8).'$'; + if(crypt($passwort,$salt) != $saved_password) { + $user = false; + } + } else { + //* The password is md5 encrypted + if(md5($passwort) != $saved_password) { + $user = false; + } + } + } else { + $user = false; + } } - $user = $app->db->queryOneRecord($sql); + if($user) { if($user['active'] == 1) { // User login right, so attempts can be deleted diff --git a/interface/web/login/lib/lang/en.lng b/interface/web/login/lib/lang/en.lng index 0bfe02a26..9f93331b8 100644 --- a/interface/web/login/lib/lang/en.lng +++ b/interface/web/login/lib/lang/en.lng @@ -1,15 +1,18 @@ - 64 characters.'; + ?> \ No newline at end of file diff --git a/interface/web/login/lib/lang/es.lng b/interface/web/login/lib/lang/es.lng index 19c223331..f51ac8a19 100644 --- a/interface/web/login/lib/lang/es.lng +++ b/interface/web/login/lib/lang/es.lng @@ -1,12 +1,14 @@ - + 64 characters.'; +?> diff --git a/interface/web/login/lib/lang/fr.lng b/interface/web/login/lib/lang/fr.lng index e142b6e94..d0d6b8172 100644 --- a/interface/web/login/lib/lang/fr.lng +++ b/interface/web/login/lib/lang/fr.lng @@ -1,12 +1,14 @@ - + 64 characters.'; +?> diff --git a/interface/web/login/lib/lang/it.lng b/interface/web/login/lib/lang/it.lng index 55d980ec5..35941734f 100644 --- a/interface/web/login/lib/lang/it.lng +++ b/interface/web/login/lib/lang/it.lng @@ -1,12 +1,14 @@ - + 64 characters.'; +?> diff --git a/interface/web/login/lib/lang/nl.lng b/interface/web/login/lib/lang/nl.lng index 28dfc7318..ef775cdd8 100644 --- a/interface/web/login/lib/lang/nl.lng +++ b/interface/web/login/lib/lang/nl.lng @@ -1,12 +1,14 @@ - + 64 characters.'; +?> diff --git a/interface/web/login/lib/lang/se.lng b/interface/web/login/lib/lang/se.lng index 706aa5c3e..e6172cfbd 100644 --- a/interface/web/login/lib/lang/se.lng +++ b/interface/web/login/lib/lang/se.lng @@ -1,12 +1,14 @@ - + 64 characters.'; +?> diff --git a/interface/web/login/password_reset.php b/interface/web/login/password_reset.php index 23516f355..4b39def30 100644 --- a/interface/web/login/password_reset.php +++ b/interface/web/login/password_reset.php @@ -1,78 +1,88 @@ -uses('tpl'); -$app->tpl->newTemplate("form.tpl.htm"); -$app->tpl->setInclude('content_tpl','templates/password_reset.htm'); - -$app->tpl_defaults(); - -include(ISPC_ROOT_PATH.'/web/login/lib/lang/'.$_SESSION['s']['language'].'.lng'); -$app->tpl->setVar($wb); - -if(isset($_POST['username']) && $_POST['username'] != '' && $_POST['email'] != '' && $_POST['username'] != 'admin') { - - $username = $app->db->quote($_POST['username']); - $email = $app->db->quote($_POST['email']); - - $client = $app->db->queryOneRecord("SELECT * FROM client WHERE username = '$username' && email = '$email'"); - - if($client['client_id'] > 0) { - $new_password = md5 (uniqid (rand())); - $new_password = $app->db->quote($new_password); - $username = $app->db->quote($client['username']); - $app->db->query("UPDATE sys_user SET passwort = md5('$new_password') WHERE username = '$username'"); - $app->db->query("UPDATE client SET ´password´ = md5('$new_password') WHERE username = '$username'"); - $app->tpl->setVar("message",$wb['pw_reset']); - - mail($client['email'],$wb['pw_reset_mail_title'],$wb['pw_reset_mail_msg'].$new_password); - - } else { - $app->tpl->setVar("message",$wb['pw_error']); - } - -} else { - $app->tpl->setVar("message",$wb['pw_error_noinput']); -} - - - -$app->tpl_defaults(); -$app->tpl->pparse(); - - - - - +uses('tpl'); +$app->tpl->newTemplate("form.tpl.htm"); +$app->tpl->setInclude('content_tpl','templates/password_reset.htm'); + +$app->tpl_defaults(); + +include(ISPC_ROOT_PATH.'/web/login/lib/lang/'.$_SESSION['s']['language'].'.lng'); +$app->tpl->setVar($wb); + +if(isset($_POST['username']) && $_POST['username'] != '' && $_POST['email'] != '' && $_POST['username'] != 'admin') { + + if(!preg_match("/^[\w\.\-\_]{1,64}$/", $_POST['username'])) die($app->lng('user_regex_error')); + if(!preg_match("/^\w+[\w.-]*\w+@\w+[\w.-]*\w+\.[a-z]{2,10}$/i", $_POST['email'])) die($app->lng('email_error')); + + $username = $app->db->quote($_POST['username']); + $email = $app->db->quote($_POST['email']); + + $client = $app->db->queryOneRecord("SELECT * FROM client WHERE username = '$username' AND email = '$email'"); + + if($client['client_id'] > 0) { + $new_password = md5 (uniqid (rand())); + $salt="$1$"; + for ($n=0;$n<11;$n++) { + $salt.=chr(mt_rand(64,126)); + } + $salt.="$"; + $new_password_encrypted = crypt($new_password,$salt); + $new_password_encrypted = $app->db->quote($new_password_encrypted); + + $username = $app->db->quote($client['username']); + $app->db->query("UPDATE sys_user SET passwort = '$new_password_encrypted' WHERE username = '$username'"); + $app->db->query("UPDATE client SET ´password´ = '$new_password_encrypted' WHERE username = '$username'"); + $app->tpl->setVar("message",$wb['pw_reset']); + + mail($client['email'],$wb['pw_reset_mail_title'],$wb['pw_reset_mail_msg'].$new_password); + + } else { + $app->tpl->setVar("message",$wb['pw_error']); + } + +} else { + $app->tpl->setVar("message",$wb['pw_error_noinput']); +} + + + +$app->tpl_defaults(); +$app->tpl->pparse(); + + + + + ?> \ No newline at end of file diff --git a/interface/web/tools/form/user_settings.tform.php b/interface/web/tools/form/user_settings.tform.php index 05b3e8c0f..516031a18 100644 --- a/interface/web/tools/form/user_settings.tform.php +++ b/interface/web/tools/form/user_settings.tform.php @@ -1,143 +1,144 @@ - 0 id must match with id of current user -$form['auth_preset']['userid'] = 0; -//* 0 = default groupid of the user, > 0 id must match with groupid of current user -$form['auth_preset']['groupid'] = 0; - -//** Permissions are: r = read, i = insert, u = update, d = delete -$form['auth_preset']['perm_user'] = 'riud'; -$form['auth_preset']['perm_group'] = 'riud'; -$form['auth_preset']['perm_other'] = ''; - -//* Languages -$language_list = array(); -$handle = @opendir(ISPC_ROOT_PATH.'/lib/lang'); -while ($file = @readdir ($handle)) { - if ($file != '.' && $file != '..') { - if(@is_file(ISPC_ROOT_PATH.'/lib/lang/'.$file) and substr($file,-4,4) == '.lng') { - $tmp = substr($file, 0, 2); - $language_list[$tmp] = $tmp; - } - } -} - -$form['tabs']['users'] = array ( - 'title' => 'Settings', - 'width' => 80, - 'template' => 'templates/user_settings.htm', - 'fields' => array ( - ################################## - # Beginn Datenbankfelder - ################################## - 'passwort' => array ( - 'datatype' => 'VARCHAR', - 'formtype' => 'PASSWORD', - 'regex' => '', - 'errmsg' => '', - 'default' => '', - 'value' => '', - 'separator' => '', - 'width' => '15', - 'maxlength' => '100', - 'rows' => '', - 'cols' => '' - ), - 'language' => array ( - 'datatype' => 'VARCHAR', - 'formtype' => 'SELECT', - 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', - 'errmsg'=> 'language_is_empty'), - 1 => array ( 'type' => 'REGEX', - 'regex' => '/^[a-z]{2}$/i', - 'errmsg'=> 'language_regex_mismatch'), - ), - 'regex' => '', - 'errmsg' => '', - 'default' => '', - 'value' => $language_list, - 'separator' => '', - 'width' => '30', - 'maxlength' => '2', - 'rows' => '', - 'cols' => '' - ) - ################################## - # ENDE Datenbankfelder - ################################## - ) -); - - + 0 id must match with id of current user +$form['auth_preset']['userid'] = 0; +//* 0 = default groupid of the user, > 0 id must match with groupid of current user +$form['auth_preset']['groupid'] = 0; + +//** Permissions are: r = read, i = insert, u = update, d = delete +$form['auth_preset']['perm_user'] = 'riud'; +$form['auth_preset']['perm_group'] = 'riud'; +$form['auth_preset']['perm_other'] = ''; + +//* Languages +$language_list = array(); +$handle = @opendir(ISPC_ROOT_PATH.'/lib/lang'); +while ($file = @readdir ($handle)) { + if ($file != '.' && $file != '..') { + if(@is_file(ISPC_ROOT_PATH.'/lib/lang/'.$file) and substr($file,-4,4) == '.lng') { + $tmp = substr($file, 0, 2); + $language_list[$tmp] = $tmp; + } + } +} + +$form['tabs']['users'] = array ( + 'title' => 'Settings', + 'width' => 80, + 'template' => 'templates/user_settings.htm', + 'fields' => array ( + ################################## + # Beginn Datenbankfelder + ################################## + 'passwort' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'PASSWORD', + 'encryption'=> 'CRYPT', + 'regex' => '', + 'errmsg' => '', + 'default' => '', + 'value' => '', + 'separator' => '', + 'width' => '15', + 'maxlength' => '100', + 'rows' => '', + 'cols' => '' + ), + 'language' => array ( + 'datatype' => 'VARCHAR', + 'formtype' => 'SELECT', + 'validators' => array ( 0 => array ( 'type' => 'NOTEMPTY', + 'errmsg'=> 'language_is_empty'), + 1 => array ( 'type' => 'REGEX', + 'regex' => '/^[a-z]{2}$/i', + 'errmsg'=> 'language_regex_mismatch'), + ), + 'regex' => '', + 'errmsg' => '', + 'default' => '', + 'value' => $language_list, + 'separator' => '', + 'width' => '30', + 'maxlength' => '2', + 'rows' => '', + 'cols' => '' + ) + ################################## + # ENDE Datenbankfelder + ################################## + ) +); + + ?> \ No newline at end of file -- GitLab