public function login($username = NULL, $password = NULL, $remember = FALSE) { if (!$username && !$password && $this->exists()) { // Logs user in when the cookie hash value is matching the one in the database. // Logs user in Session::put($this->_sessionName, $this->data()->id); } else { $user = $this->find($username); if ($user) { if ($this->data()->password === Hash::make($password, $this->_data->salt)) { Session::put($this->_sessionName, $this->data()->id); if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); if (!$hashCheck->count()) { $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; } Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } return TRUE; } } } return false; }
public static function login($username = null, $password = null, $remember = null) { if ($username != null && $password != null) { $class = Config::get('user/user_class'); $user = $class::find($username, Config::get('user/userField')); //echo '<pre>'; //var_dump($user); //echo '</pre>'; //die(); if ($user != null) { if ($user->{Config::get('user/passwordField')} === Hash::make($password)) { //Estas Dos Lineas Loguean realmente al Usuario Session::put(Config::get('session/session_name'), $user); Session::put('isLoggedIn', true); if (Config::get('groups/active')) { Session::put('listPermission', self::getPermissions($user)); } if ($remember && Config::get('session/active')) { $hash = Hash::unique(); $hashCheck = DB::getInstance()->table(Config::get('session/table'))->where(Config::get('session/primaryKey'), $user->{$user->getInfo('primaryKey')})->first(); if ($hashCheck == null) { DB::getInstance()->table(Config::get('session/table'))->insert([Config::get('session/primaryKey') => $user->{$user->getInfo('primaryKey')}, Config::get('session/hashField') => $hash]); } else { $hash = $hashCheck->{Config::get('session/hashField')}; } Cookie::put(Config::get('remember/cookie_name'), $hash, Config::get('remember/cookie_expiry')); } return true; } } } return false; }
public function login($username = null, $password = null, $remember = false) { //print_r($this->_data); if (!$username && !$password && $this->exists()) { //Log User In by setting a session Session::put($this->_sessionName, $this->data()->id); } else { $user = $this->find($username); if ($user) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { Session::put($this->_sessionName, $this->data()->id); //If user has clicked 'remember', this code below iis going to be run if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); if (!$hashCheck->count()) { $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; } Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } return true; } } } return false; }
public function login($username = NULL, $password = NULL, $remember = FALSE) { $user = $this->find($username); if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); } else { if ($user) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { Session::put($this->_sessionName, $this->data()->id); if ($remember) { $hash = Hash::unique(); // Check if a Hash is stored in the database in the table "users_session" $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); // if no Hash is found in the table "users_session", insert a Hash with the hash that is generated above. if (!$hashCheck->count()) { $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { // If a Hash is FOUND in the table "users_session" store the HASH value in the variable $hash. $hash = $hashCheck->first()->hash; } Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } return TRUE; } } } return FALSE; }
public function Authenticate($Username = false, $Password = false, $Remember = false) { if ($Username !== false && $Password !== false) { //Confirm Input $UserData = DB::getInstance()->table("Users")->where("Username", $Username)->get(1)[0]; $HashedPassAttempt = Hash::make(Input::get("Password"), $UserData->Salt); if ($HashedPassAttempt == $UserData->Password) { Session::put("UserID", $UserData->UserID); if ($Remember == 'on') { //Was Remember Me Checkbox ticked? $hashCheck = DB::getInstance()->table("user_sessions")->where('user_id', $UserData->UserID)->get(); //Check for existing session if (count($hashCheck) == 0) { //If there is not an existing hash $hash = Hash::unique(); DB::getInstance()->table('user_sessions')->insert(array('user_id' => $UserData->UserID, 'hash' => $hash)); } else { //use existing hash if found $hash = $hashCheck[0]->hash; } $Cookie = Cookie::put(Config::get("remember/cookie_name"), $hash, Config::get("remember/cookie_expiry")); //Set cookie } return $this->form($UserData->UserID); //Return User MetaTable } else { throw new Exception('Invalid Username or Password'); } } else { throw new Exception('Invalid Username or Password'); } return false; }
public function login($username = null, $password = null, $remember = false) { if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); return true; } else { if ($username && $password) { $user = $this->find($username); if ($user) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { // Check if the user account is activated if ((int) $this->data()->active == 0) { throw new Exception(lang('ACCOUNT_INACTIVATED')); return false; } Session::put($this->_sessionName, $this->data()->id); if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); if (!$hashCheck->count()) { $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; } Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } return true; } } } } throw new Exception("Incorrect Username/password."); return false; }
public function authorize($login, $password, $remember) { $config = Service::get('config'); $db = Service::get('pdo'); $query = $db->prepare("SELECT * FROM `user` WHERE `email`= :email AND `password`= :password"); $query->execute(array(':email' => $login, ':password' => md5($password))); $user = $query->fetchObject(); $userid = $user->id; if ($user->password === md5($password)) { if ($remember === 'on') { $hash = hash('sha256', uniqid()); $hashcheck = $user->hash; if (!$hashcheck) { $query = $db->prepare("UPDATE `user` SET `hash` = :hash WHERE `id` = :id"); $query->execute(array(':hash' => $hash, ':id' => $userid)); } else { $hash = $user->hash; } Cookie::put($config->getVal('remember/cookie_name'), $hash, $config->getVal('remember/cookie_expiry')); } if ($userid) { $this->user = $user; $session = Service::get('session'); $session->set($config->getVal('session/session_name'), $userid); } return $userid; } }
public function login($username = null, $password = null, $remember = false) { if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); } else { //finding the username $user = $this->find($username); //if username exists check password if ($user) { //check password by hashing if ($this->data()->password === Hash::make($password, $this->data()->salt)) { Session::put($this->_sessionName, $this->data()->id); //put this user id in session //check if remember me checked if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); //check if already hash for cookie is set for this user in session database if (!$hashCheck->count()) { //if not then set a hash for this user's cookie $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; } //put the hash cookie Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } return true; } } } return false; }
public function __construct($user = null) { $this->_db = DB::getInstance(); $this->session_name = Config::get('session/session_name'); $this->_cookieName = Config::get('remember/cookie_name'); if (!$user) { if (Session::exists($this->session_name)) { if ($this->find_by_id(Session::get($this->session_name))) { $this->_isLoggedIn = true; } else { // logout process $this->logout(); } } elseif (Cookie::exists($this->_cookieName)) { $this->_db->get('user_id', 'users_session', array('hash', '=', Cookie::get($this->_cookieName))); if ($this->find_by_id($this->_db->first()->user_id)) { Session::put($this->session_name, $this->data()->id); Cookie::put($this->_cookieName, Cookie::get($this->_cookieName), Config::get('remember/cookie_expiry')); Session::flash('success', 'Wellcome Back ' . $this->data()->username); $this->_isLoggedIn = true; } else { $this->logout(); } } } elseif (is_numeric($user)) { if ($this->find_by_id($user)) { Session::put($this->session_name, $this->data()->id); $this->_isLoggedIn = true; } else { $this->logout(); } } elseif (is_string($user)) { return $this->find($user); } }
/** * Description * @param string $email * @param string $password * @param boolean $remember * @return boolean */ public function login($email = null, $password = null, $remember = false) { if ($email === null && $password === null && $this->exists()) { Session::put(Config::get('session/name'), $this->data()->id); } else { $employeeExists = $this->find($email); $passwordCheck = password_verify($password, $this->data()->password_hash); if ($employeeExists && $passwordCheck) { Session::put(Config::get('session/name'), $this->data()->id); if ($remember) { /** * this additional check accounts for possibility that old session * hash hasn't been deleted from database so that same employee won't * be inserted in employee_session table twice **/ $oldRecord = $this->database->get('employee_session', ['employee_id', '=', $this->data()->id]); if ($oldRecord->count()) { $hash = $oldRecord->first()->hash; } else { $hash = bin2hex(openssl_random_pseudo_bytes(32)); $this->database->insert('employee_session', ['employee_id' => $this->data()->id, 'hash' => $hash]); } Cookie::put(Config::get('cookie_to_remember_employee_session/name'), $hash, Config::get('cookie_to_remember_employee_session/exptime')); } return true; } } return false; }
public function login($username = null, $password = null, $remember = false) { if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); } else { $user = $this->find($username); if ($user) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { Session::put($this->_sessionName, $this->data()->id); if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); if (!$hashCheck->count()) { $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; } Cookie::put($this->_cookieName, $hash, Config::get('remember.cookie_expiry')); } return true; } } } return false; }
public static function forceLogin($user = null, $remember = false) { if ($user->exists()) { DB::instance()->delete("user_sessions", array("", "hash", "=", Cookie::get(Config::get('remember/cookie_name')))); Session::put(Config::get('session/loggedId'), $user->id()); if ($remember) { $hash = Hash::hashUnique(); DB::instance()->insert("user_sessions", array('user_id' => $user->id(), 'hash' => $hash, 'expiry' => DateFormat::sql(time() + Config::get('remember/cookie_expiry')))); Cookie::put(Config::get('remember/cookie_name'), $hash, Config::get('remember/cookie_expiry')); } self::$_currentUser = new User(); } }
public static function Create($Key = 0, $Company = false) { $Return = false; if ($Key !== 0) { if (\Session::exists("refKey")) { if (\Session::get("refKey") != $Key) { //This computer has multiple Keys? I'm not sure how or why this would happen. //It is a possibility so I guess I should probably plan for it $SavedKey = new Key(\Session::get("refKey")); if ($SavedKey->validKey()) { //Has two valid keys? What on earth? I will have to account for this later } else { \Session::put("refKey", $Key); $Return = true; } } } else { \Session::put("refKey", $Key); $Return = true; } if (\Cookie::exists("refKey")) { if (\Cookie::get("refKey") != $Key) { $SavedKey = new Key(\Cookie::get("refKey")); if ($SavedKey->validKey()) { //Has two valid keys? What on earth? I will have to account for this later } else { \Cookie::put("refKey", $Key, \Config::get("tracking/cookie_expiry")); $Return = true; } } } else { \Cookie::put("refKey", $Key, \Config::get("tracking/cookie_expiry")); $Return = true; } if ($Company != false) { if (count(\DB::getInstance()->table("companyip")->where("IP", \Connection::IP())->where("Company", $Company->ID())) == 0) { \DB::getInstance()->table("companyip")->insert(array("IP" => \Connection::IP(), "Company" => $Company->ID(), "LastScene" => \Time::get(), "Hits" => 1)); } else { \DB::getInstance()->table("companyip")->where("IP", \Connection::IP())->increment("Hits"); } } //IP Based Search will go here return $Return; } return false; }
public function post_test() { if (Auth::guest()) { Cookie::put('sapoc_new_offer', json_encode(Input::get()), 30, '/', URL::base()); Log::info('Cookied'); } // $creds = array( // 'username' => Input::get('email'), // 'password' => Input::get('password') // ); // if (Auth::attempt($creds)) { // echo 'Data saved'; // } else { // return Redirect::to('ref/test') // ->with_input() // ->with('login_errors', true); // } }
public function authenticate() { // Create an consumer from the config $consumer = Consumer::make($this->config); // Load the provider $provider = Provider::make($this->provider); // Create the URL to return the user to $callback = array_get($this->config, 'callback') ?: \URL::to(\Config::get('oneauth::urls.callback', 'connect/callback'), null, false, false); $callback = rtrim($callback, '/') . '/' . $this->provider; // Add the callback URL to the consumer $consumer->callback($callback); // Get a request token for the consumer $token = $provider->request_token($consumer); // Store the token \Cookie::put('oauth_token', base64_encode(serialize($token))); // Redirect to the twitter login page return \Redirect::to($provider->authorize_url($token, array('oauth_callback' => $callback))); }
public function action_new_post() { if (Auth::guest()) { $page = Input::get('offer_type') == 1 ? 'offers/new_freight' : 'offers/new_trans'; Cookie::put('rid', $page); return Redirect::to('login')->with_input(); } $input = array('user_id' => Input::get('user_id'), 'offer_type' => Input::get('offer_type'), 'from_date' => $this->mysql_date(Input::get('from_date')), 'to_date' => $this->mysql_date(Input::get('to_date')), 'from_country' => Input::get('from_country'), 'from_state' => Input::get('from_state'), 'from_town' => Input::get('from_town'), 'to_country' => Input::get('to_country'), 'to_state' => Input::get('to_state'), 'to_town' => Input::get('to_town'), 'auto_type' => Input::get('auto_type'), 'auto_load_type' => Input::get('auto_load_type'), 'auto_capacity' => Input::get('auto_capacity'), 'auto_volume' => Input::get('auto_volume'), 'auto_price' => Input::get('auto_price'), 'auto_count' => Input::get('auto_count'), 'auto_license' => Input::get('auto_license'), 'comments' => Input::get('comments')); $rules = array('offer_type' => 'required', 'from_date' => 'required', 'to_date' => 'required', 'from_country' => 'required', 'from_town' => 'required', 'to_country' => 'required', 'to_town' => 'required', 'auto_type' => 'required', 'auto_capacity' => 'numeric|required', 'auto_count' => 'integer', 'auto_price' => 'numeric'); $v = Validator::make($input, $rules); if ($v->fails()) { $page = $input['offer_type'] == 1 ? 'offers/new_freight' : 'offers/new_trans'; return Redirect::to($page)->with_errors($v)->with_input(); } else { $offer = new Offer($input); $offer->save(); return View::make('sapoc.pages.result')->with('message', __('offers-new.save-success')); } }
public function setScore($id, $hiscore) { switch ($this->_result) { //switch through cases of result case 'won': //if won $score = Cookie::get('score'); //get current score from cookie Cookie::put('score', $score + 1, time() + 60 * 60 * 24); //reset cookie score +1 value break; case 'lost': //if lost Cookie::put('score', 0, time() + 60 * 60 * 24); //set cookie score to 0 break; //no need for tied, because nothing happens to score } if ($hiscore < Cookie::get('score')) { //if user's hiscore is less than current score $this->_db->update('users', $id, array('hiscore' => Cookie::get('score'))); } }
public static function CheckForUpdate() { $user = new user(); if ($user->HasPermission('admin')) { // check if already checked for update if (Cookie::exists("app_version")) { $check = Cookie::get("app_version"); } else { $check = Curl::get("http://kingposter.net/update_test/?source=" . Options::get('siteurl')); Cookie::put("app_version", $check, 60 * 60 * 24 * 15); } $update = json_decode($check); if (isset($update->version)) { if (VERSION < $update->version) { if (!defined("update")) { define('UPDATE', true); } if (isset($update->message)) { Session::Flash("home", "warning", $update->message, true); } } } } }
public function adminLogin($username = null, $password = null) { if (!$username && !$password && $this->exists()) { Session::put($this->_admSessionName, $this->data()->id); } else { $user = $this->find($username); if ($user) { if (password_verify($password, $this->data()->password)) { Session::put($this->_admSessionName, $this->data()->id); $hash = Hash::unique(); $hashCheck = $this->_db->get('users_admin_session', array('user_id', '=', $this->data()->id)); if (!$hashCheck->count()) { $this->_db->insert('users_admin_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; } Cookie::put($this->_cookieName . "_adm", $hash, 3600); return true; } } } return false; }
} } if (Input::get('otpsubmit') != '') { $otp_validate = new Validate(); $otp_validation = $otp_validate->check($_POST, array('OTP' => array('required' => true, 'min' => 8, 'max' => 8))); if ($otp_validate->passed() && Token::check(Input::get('token'))) { $otp = new OTP(); if ($otp->verifyOTP(Input::get('OTP'))) { //$otp->verifyOTP(Input::get('OTP')) Session::deleteloginAttempt('OTP'); Session::put('loggedIn', 1); $log = new Log(); $log->loginLog('success'); if (Input::get('nootp') == 1) { $cookiename = 'sisnootp' . Session::get('mobile'); Cookie::put($cookiename, true, 15); unset($cookiename); } Redirect::to('home.php'); } else { $log = new Log(); $log->loginLog('wrong OTP'); Session::put('OTP Sending', 'Incorrect, Enter Again'); Session::loginAttempt('OTP'); if (Session::loginAttempts('OTP') == 3) { // blocking the user for further login!! // check whether ADMIN or any other Email-based user was trying to login if (Session::exists('student_id')) { $student = new Student(); if ($student->block(Session::get('student_id'))) { Session::destroy();
/** * Log in a user by creating a session for that user. * @param string $username * @param string $password * @param unknown $remember * @return boolean */ public function login($username = NULL, $password = NULL, $remember = false) { if (!$username && !$password && $this->exists()) { //automatically log them in Session::put($this->_sessionName, $this->data()->id); } else { $user = $this->find($username); if ($user) { //if db password matches inputted password, using same salt to check if ($this->data()->password === Hash::make($password, $this->data()->salt)) { //log in the user by creating a session //$_SESSION['user'] = user's id Session::put($this->_sessionName, $this->data()->id); if ($remember) { //user wants to be remembered $hash = Hash::unique(); //create unique hash //check if we already have a hash stored for them in the db $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); if (!$hashCheck->count()) { //if there is no hash, insert one $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { //get the hash $hash = $hashCheck->first()->hash; } //make a cookie for remember me //_cookieName = 'hash', see init.php Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } //end if //signify login is successful return true; } //end if } //end if } //end outer if //signify login has failed return false; }
/** * @depends testCookieSet * @depends testCookieExist */ public function testSessionUnset() { \Cookie::put("Test", "Hello World", 5); \Cookie::delete("Test"); $this->assertEquals(\Cookie::exists("Test"), false); }
public function login($username = null, $password = null, $remember = false) { if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); } else { $user = $this->find($username); if ($user) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { Session::put($this->_sessionName, $this->data()->id); if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get('user_session', array('user_id', '=', $this->data()->id)); if ($hashCheck->count()) { $hash = $this->_db->first()->hash; } else { $this->_db->insert('user_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } Session::flash('home', "success # Здравейте {$this->data()->name}, успешно се вписахте!"); Redirect::to('index.php'); return true; } else { Session::flash('home', "danger # Въвели сте грешна парола."); Redirect::to('login.php'); } } else { Session::flash('home', "danger # Въвели сте грешнo потребителско име."); Redirect::to('login.php'); } } return false; }
} Session::flash('failure_post', '<div class="alert alert-danger alert-dismissable"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span></button>' . $error_string . '</div>'); } } else { // Invalid token - TODO: improve //echo 'Invalid token'; } } // Generate a post token if ($user->isLoggedIn()) { $token = Token::generate(); } // View count if (!Cookie::exists('nl-topic-' . $tid)) { $queries->increment("topics", $tid, "topic_views"); Cookie::put("nl-topic-" . $tid, "true", 3600); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="description" content="<?php echo $sitename; ?> Forum - Topic: <?php echo htmlspecialchars($topic->topic_title); ?>
public function login($username = null, $password = null, $remember = false) { if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); } else { $user = $this->find($username); if ($user) { if ($this->checkPassword($password)) { Session::put($this->_sessionName, $this->data()->id); $ip = $_SERVER['REMOTE_ADDR']; $change = $this->_db->get('members', array('last_ip', '=', $ip))->results(); if (count($change) && $change[0]->id != Session::get('user')) { foreach ($change as $ch) { $this->_db->update('members', $ch->id, array('last_ip' => 0)); } } $this->_db->update('members', Session::get('user'), array('last_ip' => $ip)); if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); if (!$hashCheck->count()) { $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; } if (!Cookie::put($this->_cookieName, $hash, Config::get('remember/expires'))) { return false; } } $this->_isLoggedIn = true; return true; } } return false; } }
public function login($username = null, $password = null, $remember = true) { if (!$username && !$password && $this->exists()) { //if username and password aren't set, but user exists Session::put($this->_sessionName, $this->data()->id); //put user's id into session array } else { $user = $this->find($username); //else, find user with $username and set it to $user if ($user) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { //set this user's password to a hash of the password and salt Session::put($this->_sessionName, $this->data()->id); //set the default session to the user's id if ($remember) { //if remember option was set $hash = Hash::unique(); //create unique hash $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); //get user's unique hash, stored in users_session table, by user_id if (!$hashCheck->count()) { //if hashCheck (remember) doesn't have a count (doesn't exist) $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; //if it exists, set it to $hash } Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); //set the $hash as a cookie } return true; } } } return false; }
/** * This method logs the user in or returns a session if they are already logged in. If no arguments are passed it is assumed the user is logged in already * (i.e. their cookie stores a valid hash). Otherwise you pass the $username, $password, and whether or not the user asked to be remembered ($remember). * If the $username and hashed $password match that which is stored in the database the user is logged in. * If the user has clicked 'remember me' then a cookie is also stored with a hash in order to keep the user logged in. */ public function login($username = null, $password = null, $remember = false) { if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); } else { $user = $this->find($username); //Otherwise, find the user. if ($user) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { Session::put($this->_sessionName, $this->data()->id); //If the password was correct, put a session. if ($remember) { $hash = Hash::unique(); //Create a unique hash. //Check whether a hash exists in the 'users_session' table for that user already i.e. they have logged in previously and asked to be remembered. $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); if (!$hashCheck->count()) { //Insert a hash into the database for the user. $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; //Take the first row and the value stored for hash and save it in the local variable $hash. } Cookie::put($this->_cookieName, $hash, Configurations::get('remember/cookie_expiry')); //store the hash in a cookie Cookie::put($this->_cookieName2, $this->data()->id, Configurations::get('remember/cookie_expiry')); //store the userID in a cookie } return true; } } } return false; }
/** * Write the session cookie. * * @return void */ private static function write_cookie() { if (!headers_sent()) { $minutes = Config::get('session.expire_on_close') ? 0 : Config::get('session.lifetime'); Cookie::put('laravel_session', static::$session['id'], $minutes, Config::get('session.path'), Config::get('session.domain'), Config::get('session.https'), Config::get('session.http_only')); } }
require_once 'core/init.php'; if (Session::exists('home')) { //if session "home" exists echo Session::flash('home'); //flash message of home } $user = new User(); //instantiante new user if ($user->isLoggedIn()) { //if user is logged in require_once 'includes/templates/home.php'; //require home page template if (!Cookie::exists('score')) { //if cookie score doesn't exist Cookie::put('score', 0, time() + 60 * 60 * 24); //set a cookie of a score of 0 } if (Input::exists()) { //if input (post) exists $game = new Game(); //instantiate new game $game->randomHand(); //generate a computer's random hand $game->play(Input::get('hand')); //play player's hand (from input) $computerHand = $game->computerHand(); //set the computer's hand $result = $game->result(); //set the result Session::put('computerHand', $computerHand);
/** * funktion um einen user ein-zu-loggen * falls er wählt, dass sich die seite an ihn erinnern soll, wird überprüft ob der user in der db * bereits einen unique id hat, sonst wird eine erzeugt. diese id wird dann in ein cookie geschrieben * wenn der user das nächste mal kommt und die id für einen existierenden user im cookie vorhanden ist, wird der user * automatisch eingeloggt * * @param null $username name des users, der sich versucht einzuloggen * @param null $password passwort des users * @param bool $remember will der user, dass er von nun an automatisch eingeloggt wird * @return bool status ob login erfolgreich war */ public function login($username = null, $password = null, $remember = false) { //hier landet das login, wenn man remember me hat //es wird geprüft ob es daten im _data - array hat, wenn es welche hat, wird der user anhand dieser daten eingeloggt if (!$username && !$password && $this->exists()) { Session::put($this->_sessionName, $this->data()->id); } else { $user = $this->find($username); if ($user) { if (password_verify($password, $this->data()->password)) { /** * nach einem erfolgreichem login wird eine session erstellt * die session enthält unsere id */ Session::put($this->_sessionName, $this->data()->id); /** * falls der user sicht nicht mehr selber einloggen will, * sondern direkt automatisch eingeloggt wird */ if ($remember) { //echo 'in if schlaufe angekommen'; check $hash = Hash::unique(); //sollte eigentlich nicht vorkommen, wird zur sicherheit dennoch überprüft //wenn der user bereits einen solchen hash besitzt, müsste er automatisch eingeloggt sein. es ist also eine sicherheitsmasnahme $hashCheck = $this->_db->get('users_session', array('user_id', '=', $this->data()->id)); //echo'einen schritt weiter'; check //hier wird geprüft ob der user bereits eine gespeicherte session besitzt if (!$hashCheck->count()) { //echo 'keine session in db';check //falls er keine hat, wird der generierte hash zusammen mit der id des users in der datenbank gespeichert $this->_db->insert('users_session', array('user_id' => $this->data()->id, 'hash' => $hash)); //falls der user bereits einen hash für eine session besitzt, wird dieser verwendet } else { $hash = $hashCheck->first()->hash; } //der hash wird nun im cookie gespeichert Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } return true; } } } return false; }