Moderators: macek, egami, gesf

//this function is called on my login page once credentials have been verified.
private function login_success($record)//$record holds user record from database
{
$_SESSION['uid']=$record['id'];
$_SESSION['firstName']=$record['first_name'];
$_SESSION['lastName']=$record['last_name'];
$_SESSION['email']=$record['email'];
$_SESSION['user_type_id']=$record['user_type_id'];
if (isset($_POST['mem']))//this is a 'remember me' checkbox.
{ //wants to be remembered
setcookie('pw',$record['password'],time()+3600*24*30);//this is a salted hashed password
setcookie('id',$_SESSION['uid'], time()+3600*24*30);//and a unique id that the person never sees
}
redirect_to('dashboard.php');//and then go to dashboard
}
class User {
function __construct()
{
if (! empty($_SESSION['email'])){redirect_to('dashboard.php');}
if (isset($_COOKIE['id']) && isset($_COOKIE['pw'])) // has login cookie
{
$salt = substr($_COOKIE['pw'],32);
$arecord = self::find_by_id($_COOKIE['id']);
if ($_COOKIE['pw']===$arecord['password']) //successful
{
self::login_success($arecord);
} else {
setcookie('id',$_COOKIE['id'],1);
redirect_to('login.php?cookiefail=1');
}
}
$record=self::login($_POST['un'],$_POST['pw']);
if (! isset($record['email'])){
redirect_to("login.php?fail=1");
} else {
self::login_success($record);
}
}

Users browsing this forum: No registered users and 1 guest