[eluser]A.M.F[/eluser]
the third part of my application is the
user_lib.php library. in there i have the login checking and the auth() function that checks if the user has authoration and to see if he is looged with cookies or sessions.
user_lib.php
Code:
class User_lib
{
var $object;
function User_lib()
{
$this->object =& get_instance();
}
// --------------------------------------------------------------------
/**
* Checks if the login information is true
*
* @access public
* @param string name
* @param string password
*
* @return boolean true or false if login correct
*/
function login($user, $pass)
{
/*see if the username and the password matches, if so return true*/
//$info['password'] = md5(sha1($info['password'])); //encrypting the password
$this->object->db->from('users');
$this->object->db->where('username', $user);
$this->object->db->where('password', $pass);
$query = $this->object->db->get();
if ($query->num_rows() == 0) //שם המשתמש או הסיסמא אינם נכונים
{
return FALSE;
}
else
{
$x = $query->row();
if ($pass != $x->password) //checks if the pass entered matches the password
{
return FALSE;
}
else
{
return TRUE;
}
}
}
// --------------------------------------------------------------------
/**
* Checks if the login information is true
*
* @access public
* @param string cookie name
* @param string cookie password
*
* @return boolean true or false has authoratoin
*/
function auth()
{
$cook_name = get_cookie('name');
$cook_pass = get_cookie('user');
if ((($cook_name == '')) || (($cook_pass == ''))) //don't have cookies? maybe have sessions
{
if ($this->sess_auth()) //cuz user don't want the browser to remember him
{
return TRUE;
}
else
{
return FALSE;
}
}
if (($cook_name != '') && ($cook_pass != '')) //coockie way
{
if ($this->login($cook_name, $cook_pass) == TRUE)
{
return TRUE;
}
else
{
return FALSE;
}
}
else //not loged
{
return FALSE;
}
}
//
//Session authoration
//
function sess_auth()
{
$sess_name = $this->object->session->userdata('name');
$sess_pass = $this->object->session->userdata('user');
if (isset($sess_name) && isset($sess_pass)) //session way
{
if ($this->login($sess_name, $sess_pass) == TRUE)
{
return TRUE;
}
else
{
return FALSE;
}
}
else //not loged
{
return FALSE;
}
}
}
and that is it. what do u think?
thank u for ur time!