1. Go to this page and download the library: Download gymadarasz/auth library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
gymadarasz / auth example snippets
class Auth extends Jasny\Auth
{
use Auth\Sessions;
/**
* Secret word for creating a verification hash
* @var string
*/
protected static $secret = "A random string";
/**
* Fetch a user by ID
*
* @param int $id
* @return User
*/
public static function fetchUserById($id)
{
// Database action that fetches a User object
}
/**
* Fetch a user by username
*
* @param string $username
* @return User
*/
public static function fetchUserByUsername($username)
{
// Database action that fetches a User object
}
}
class User implements Jasny\Auth\User
{
/**
* Get the user ID
*
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* Get the usermame
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Get the hashed password
*
* @return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Event called on login.
*
* @return boolean false cancels the login
*/
public function onLogin()
{
if (!$this->active) return false;
$this->last_login = new DateTime();
$this->save();
return true;
}
/**
* Event called on logout.
*/
public function onLogout()
{
$this->last_logout = new DateTime();
$this->save();
}
}