aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/functions_user.inc.php81
-rw-r--r--install/db/36-database.php47
-rw-r--r--install/phpwebgallery_structure.sql1
3 files changed, 88 insertions, 41 deletions
diff --git a/include/functions_user.inc.php b/include/functions_user.inc.php
index 6cf5de9a7..595215266 100644
--- a/include/functions_user.inc.php
+++ b/include/functions_user.inc.php
@@ -628,6 +628,28 @@ function get_language_filepath($filename)
return false;
}
+/**
+ * returns the auto login key or false on error
+ * @param int user_id
+*/
+function calculate_auto_login_key($user_id)
+{
+ global $conf;
+ $query = '
+SELECT '.$conf['user_fields']['username'].' AS username
+ , '.$conf['user_fields']['password'].' AS password
+FROM '.USERS_TABLE.'
+WHERE '.$conf['user_fields']['id'].' = '.$user_id;
+ $result = pwg_query($query);
+ if (mysql_num_rows($result) > 0)
+ {
+ $row = mysql_fetch_assoc($result);
+ $key = sha1( $row['username'].$row['password'] );
+ return $key;
+ }
+ return false;
+}
+
/*
* Performs all required actions for user login
* @param int user_id
@@ -640,44 +662,31 @@ function log_user($user_id, $remember_me)
if ($remember_me)
{
- // search for an existing auto_login_key
- $query = '
-SELECT auto_login_key
- FROM '.USERS_TABLE.'
- WHERE '.$conf['user_fields']['id'].' = '.$user_id.'
-;';
-
- $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
- if (empty($auto_login_key))
+ $key = calculate_auto_login_key($user_id);
+ if ($key!==false)
{
- $auto_login_key = base64_encode(md5(uniqid(rand(), true)));
- $query = '
-UPDATE '.USERS_TABLE.'
- SET auto_login_key=\''.$auto_login_key.'\'
- WHERE '.$conf['user_fields']['id'].' = '.$user_id.'
-;';
- pwg_query($query);
- }
- $cookie = array('id' => $user_id, 'key' => $auto_login_key);
- setcookie($conf['remember_me_name'],
- serialize($cookie),
- time()+$conf['remember_me_length'],
- cookie_path()
+ $cookie = array('id' => (int)$user_id, 'key' => $key);
+ setcookie($conf['remember_me_name'],
+ serialize($cookie),
+ time()+$conf['remember_me_length'],
+ cookie_path()
);
+ }
}
else
{ // make sure we clean any remember me ...
setcookie($conf['remember_me_name'], '', 0, cookie_path());
}
if ( session_id()!="" )
- { // this can happpen when the session is expired and auto_login
+ { // we regenerate the session for security reasons
+ // see http://www.acros.si/papers/session_fixation.pdf
session_regenerate_id();
}
else
{
session_start();
}
- $_SESSION['pwg_uid'] = $user_id;
+ $_SESSION['pwg_uid'] = (int)$user_id;
$user['id'] = $_SESSION['pwg_uid'];
}
@@ -691,25 +700,17 @@ function auto_login() {
if ( isset( $_COOKIE[$conf['remember_me_name']] ) )
{
- // must remove slash added in include/common.inc.php
$cookie = unserialize(stripslashes($_COOKIE[$conf['remember_me_name']]));
-
- $query = '
-SELECT auto_login_key
- FROM '.USERS_TABLE.'
- WHERE '.$conf['user_fields']['id'].' = '.$cookie['id'].'
-;';
-
- $auto_login_key = current(mysql_fetch_assoc(pwg_query($query)));
- if ($auto_login_key == $cookie['key'])
- {
- log_user($cookie['id'], true);
- return true;
- }
- else
+ if ($cookie!==false)
{
- setcookie($conf['remember_me_name'], '', 0, cookie_path());
+ $key = calculate_auto_login_key($cookie['id']);
+ if ($key!==false and $key===$cookie['key'])
+ {
+ log_user($cookie['id'], true);
+ return true;
+ }
}
+ setcookie($conf['remember_me_name'], '', 0, cookie_path());
}
return false;
}
diff --git a/install/db/36-database.php b/install/db/36-database.php
new file mode 100644
index 000000000..8e2662f2e
--- /dev/null
+++ b/install/db/36-database.php
@@ -0,0 +1,47 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | branch : BSF (Best So Far)
+// | file : $RCSfile$
+// | last update : $Date: 2005-09-21 00:04:57 +0200 (mer, 21 sep 2005) $
+// | last modifier : $Author: plg $
+// | revision : $Revision: 870 $
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify |
+// | it under the terms of the GNU General Public License as published by |
+// | the Free Software Foundation |
+// | |
+// | This program is distributed in the hope that it will be useful, but |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
+// | General Public License for more details. |
+// | |
+// | You should have received a copy of the GNU General Public License |
+// | along with this program; if not, write to the Free Software |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA. |
+// +-----------------------------------------------------------------------+
+
+if (!defined('PHPWG_ROOT_PATH'))
+{
+ die('Hacking attempt!');
+}
+
+$upgrade_description = 'get rid of #users.auto_login_key';
+
+$query = '
+ALTER TABLE '.PREFIX_TABLE.'users
+ DROP COLUMN auto_login_key
+;';
+pwg_query($query);
+
+echo
+"\n"
+.'"'.$upgrade_description.'"'.' ended'
+."\n"
+;
+
+?>
diff --git a/install/phpwebgallery_structure.sql b/install/phpwebgallery_structure.sql
index 4a764117d..5e1e8c162 100644
--- a/install/phpwebgallery_structure.sql
+++ b/install/phpwebgallery_structure.sql
@@ -359,7 +359,6 @@ CREATE TABLE `phpwebgallery_users` (
`username` varchar(100) binary NOT NULL default '',
`password` varchar(32) default NULL,
`mail_address` varchar(255) default NULL,
- `auto_login_key` varchar(64) default NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `users_ui1` (`username`)
) TYPE=MyISAM;