cleanup login()

git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@581 b3834d28-1941-0410-a4f8-b48e95affb8f
This commit is contained in:
cweiske 2010-01-16 08:17:35 +00:00
parent f1fcaaae0e
commit 300b829705

View file

@ -390,12 +390,28 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
function login($username, $password, $remember = FALSE) { /**
* Try to authenticate and login a user with
* username and password.
*
* @param string $username Name of user
* @param string $password Password
* @param boolean $remember If a long-time cookie shall be set
*
* @return boolean True if the user could be authenticated,
* false if not.
*/
public function login($username, $password, $remember = false)
{
$password = $this->sanitisePassword($password); $password = $this->sanitisePassword($password);
$query = 'SELECT '. $this->getFieldName('primary') .' FROM '. $this->getTableName() .' WHERE '. $this->getFieldName('username') .' = "'. $this->db->sql_escape($username) .'" AND '. $this->getFieldName('password') .' = "'. $this->db->sql_escape($password) .'"'; $query = 'SELECT '. $this->getFieldName('primary') .' FROM '. $this->getTableName() .' WHERE '. $this->getFieldName('username') .' = "'. $this->db->sql_escape($username) .'" AND '. $this->getFieldName('password') .' = "'. $this->db->sql_escape($password) .'"';
if (! ($dbresult =& $this->db->sql_query($query)) ) { if (!($dbresult = $this->db->sql_query($query))) {
message_die(GENERAL_ERROR, 'Could not get user', '', __LINE__, __FILE__, $query, $this->db); message_die(
GENERAL_ERROR,
'Could not get user',
'', __LINE__, __FILE__, $query, $this->db
);
return false; return false;
} }
@ -403,10 +419,14 @@ class SemanticScuttle_Service_User extends SemanticScuttle_DbService
$this->db->sql_freeresult($dbresult); $this->db->sql_freeresult($dbresult);
if ($row) { if ($row) {
$id = $_SESSION[$this->getSessionKey()] = $row[$this->getFieldName('primary')]; $id = $_SESSION[$this->getSessionKey()]
= $row[$this->getFieldName('primary')];
if ($remember) { if ($remember) {
$cookie = $id .':'. md5($username.$password); $cookie = $id .':'. md5($username.$password);
setcookie($this->cookiekey, $cookie, time() + $this->cookietime, '/'); setcookie(
$this->cookiekey, $cookie,
time() + $this->cookietime, '/'
);
} }
return true; return true;
} else { } else {