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 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 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 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 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) { 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 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) { //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) { if (!$username && !$password && $this->exists()) { Session::set($this->_sessionName, $this->data()->id); } else { $data = $this->_db->get("users", array("username", "=", $username)); if ($data->count()) { $this->_data = $data->get_data(); } if ($this->_data) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { Session::set($this->_sessionName, $this->data()->id); if ($remember) { $hash = Hash::unique(); $hashCheck = $this->_db->get("users_sessions", array("user_id", "=", $this->data()->id)); if (!$hashCheck->count()) { $this->_db->insert("users_sessions", array("user_id" => $this->data()->id, "hash" => $hash)); } else { $hash = $hashCheck->get_data()->hash; } Cookie::set($this->_cookieName, $hash, Config::get("remember/cookie_expiry")); } return true; } } } return false; }
/** * 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; }
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; }
public function login($user = null, $password = null, $remember = null) { if ($this->find($user) || $this->find_by_id($user)) { if ($this->user_data->password === Hash::make($password, $this->data()->salt)) { Session::put($this->session_name, $this->data()->id); if ($remember) { $hash = Hash::unique(); $fields = array("user_id" => $this->data()->id, "hash" => $hash); if ($this->_db->insert('users_session', $fields)) { COOKIE::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry')); } } return true; } else { $this->user_data = null; $this->login_errors['password'] = "******"; return false; } } else { $this->login_errors['user'] = "******"; return false; } return false; }
public function generateToken($tokenName, Hash $hash, $timestamp = false) { return $this->set($tokenName, $hash->unique(), $timestamp); }
public function login($email = null, $password = null, $remember = false) { if (!$email && !$password && $this->exist()) { $_SESSION['ID'] = $this->data()->userID; $_SESSION['role'] = $this->data()->role; } else { $user = $this->find($email); if ($user) { if ($this->data()->password === Hash::make($password, $this->data()->salt)) { $_SESSION['ID'] = $this->data()->userID; $_SESSION['role'] = $this->data()->type; if ($remember) { $hashCheck = $this->_db->get('user_session', array('userID', '=', $this->data()->userID)); if (!$hashCheck->count()) { $hash = Hash::unique(); $this->_db->insert('user_session', array('userID' => $this->data()->userID, 'hash' => $hash)); } else { $hash = $hashCheck->first()->hash; } Cookie::put($this->_cookieName, $hash, Config::get('cookie_expiry')); } $this->_isLoggedIn = true; 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('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; }
/** * 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; }
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; } }
Redirect::to('index.php'); } catch (Exception $e) { die($e->getMessage()); } } else { foreach ($validation_hurt->errors() as $error) { echo $error, '<br>'; } } } else { if ($_POST["typeOfUser"] == "robotnik") { $validation_work = $validate->check($_POST, $validate->chooseSet(1)); if ($validation_work->passed()) { $user = new User(); $salt = Hash::salt(32); $email_code = Hash::unique(); try { $user->create(array('username' => Input::get('username'), 'password' => Hash::make(Input::get('password'), $salt), 'salt' => $salt, 'email' => Input::get('email'), 'email_code' => $email_code, 'name' => Input::get('name'), 'phone_num' => Input::get('phone_num'), 'user_group' => 1, 'joined' => date('Y-m-d H:i:s'))); Session::flash('home', 'You\'ve been registered successfully! <br> The activation link has been send to your email!'); Mail::email(Input::get('email'), 'Hello' . Input::get('username') . '!', "Here is your activation link! <br> http://localhost/JagodowaPolanaOOP/activate.php?email=" . Input::get('email') . "&email_code=" . $email_code); Redirect::to('index.php'); } catch (Exception $e) { die($e->getMessage()); } } else { foreach ($validation_work->errors() as $error) { echo $error, '<br>'; } } }
/** * 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; }
public function recovery($type, $email) { $type != 'username' ? $typeMessage = 'password' : ($typeMessage = 'username'); if ($typeMessage == 'password') { $salt = Hash::salt(32); $hash = Hash::unique(); $password = substr($hash, 1, 8); $password_db = Hash::make($password, $salt); Mail::email($email, 'Hello' . $this->data()->username . '!', '<br> Here is your forgotten ' . $typeMessage . ': ' . $password); $this->update(array('password' => $password_db, 'salt' => $salt, 'password_recover' => 1), $this->data()->id); } else { if ($typeMessage == 'username') { Mail::email($email, 'Hello' . Input::get('username') . '!', '<br> Here is your forgotten ' . $typeMessage . ': ' . $this->data()->username); } } }
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; }
public function login($ident = null, $password = null) { $uname = $this->_db->query("SELECT * from user WHERE ident = ?", [$ident]); if ($uname->count()) { $uid = $uname->first()->id; $user = $this->find($uid); if ($user) { $success = false; if ($this->data()->password == password_verify($password, $this->data()->password) || $password === null) { $success = true; $_SESSION['uid'] = $uname->first()->id; $hash = Hash::unique(); if ($this->data()->last_ip != $_SERVER['REMOTE_ADDR']) { $this->_db->update("user", ["id", "=", $this->data()->id], ["last_ip" => $_SERVER['REMOTE_ADDR'], "last_ip_update" => date("Y-m-d H:i:s")]); } $hashCheck = $this->_db->get('session', ['uid', '=', $_SESSION['uid']]); if (!$hashCheck->count()) { $this->_db->insert("session", ["uid" => $_SESSION['uid'], "hash" => $hash, "ip" => $_SERVER['REMOTE_ADDR']]); } else { $x = 1; $max = $hashCheck->count(); foreach ($hashCheck->results() as $res) { if ($res->ip == $_SERVER['REMOTE_ADDR']) { $hash = $res->hash; } else { if ($x == $max) { $this->_db->insert("session", ["uid" => $_SESSION['uid'], "hash" => $hash, "ip" => $_SERVER['REMOTE_ADDR']]); } } } } setcookie("uniqid", $hash, 2147483647); $this->_loggedIn = true; } $this->_db->insert("logs", ["type" => 2, "data" => json_encode(["UID" => $uid, "password" => base64_encode($success ? "HIDDEN" : $password), "ip" => $_SERVER['REMOTE_ADDR']]), "success" => $success ? 1 : 0]); if ($success) { return true; } } } $this->_loggedIn = false; $this->_data = []; return false; }
<?php session_start(); require_once 'functions/sanitize.php'; require_once 'functions/protect.php'; $GLOBALS['config'] = array('mysql' => array('host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'db' => 'JagodowaPolanaOOP'), 'remember' => array('cookie_name' => 'hash', 'cookie_expiry' => 604800), 'session' => array('session_name' => 'user', 'token_name' => 'token')); spl_autoload_register(function ($class) { require_once 'classes/' . $class . '.php'; }); if (Cookie::exists(Config::get('remember/cookie_name')) && !Session::exists(Config::get('session/session_name'))) { $hash = Cookie::get(Config::get('remember/cookie_name')); $hashCheck = DB::getInstance()->get('users_session', array('hash', '=', $hash)); if ($hashCheck->count()) { $user = new User($hashCheck->first()->user_id); $user->login(); $hash_unique = Hash::unique(); DB::getInstance()->update('users_session', $user->data()->id, array('hash' => $hash_unique)); Cookie::update(Config::get('remember/cookie_name'), $hash_unique, Config::get('remember/cookie_expiry')); } }