本文整理汇总了PHP中Hash::unique方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::unique方法的具体用法?PHP Hash::unique怎么用?PHP Hash::unique使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::unique方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: login
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;
}
示例2: login
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;
}
示例3: login
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;
}
示例4: login
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;
}
示例5: login
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;
}
示例6: Authenticate
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;
}
示例7: login
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;
}
示例8: login
/**
* 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;
}
示例9: login
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;
}
示例10: login
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'] = "password is incorrect";
return false;
}
} else {
$this->login_errors['user'] = "user not found in databases";
return false;
}
return false;
}
示例11: generateToken
public function generateToken($tokenName, Hash $hash, $timestamp = false)
{
return $this->set($tokenName, $hash->unique(), $timestamp);
}
示例12: login
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;
}
示例13: login
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;
}
示例14: login
/**
* 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;
}
示例15: login
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;
}
}