PHP Класс A1_Core

bcrypt is highly recommended by many to safely store passwords. For more information, see http://codahale.com/how-to-safely-store-a-password/ Based on Kohana's AUTH, Fred Wu's AUTHLITE and Woody Gilk's Bonafide
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$_config
$_name
$_sess
$_user

Открытые методы

Метод Описание
check ( $password, $hash ) : boolean Checks if password matches hash
check_password ( $user, $password ) : boolean Validates a password against a user. This can be used to confirm user in actions where you ask for password while user is logged in to be extra safe (eg when deleting account)
complete_login ( $user, $remember = FALSE ) : TRUE Updates session, set remember cookie (if required)
failed_login ( $user ) : FALSE Registers a failed login attempt
get_user ( ) : object Returns the user - if any
hash ( $input, $salt = NULL, $cost = NULL ) : string Generates bcrypt hash for input
instance ( $_name = 'a1' ) : object Return a static instance of A1.
logged_in ( ) : boolean Returns TRUE is a user is currently logged in
login ( $username, $password, $remember = FALSE ) : mixed Attempt to log in a user.
logout ( $destroy = FALSE ) : boolean Log out a user by removing the related session variables.
session ( $id = NULL ) : Session (Initializes &) Returns the session we're working with
set_user ( $user ) : object Sets the user that is logged in
store_user_in_session ( $user ) : void Stores user model in session

Защищенные методы

Метод Описание
__construct ( $_name = 'a1', $_config ) : void Loads Session and configuration options.
_get_failed_attempts ( $user ) : void Returns the number of failed login attempts
_increment_failed_attempts ( $user ) : void Increment the number of failed login attempts since last successfull login
_increment_logins ( $user ) : void Increment the number of logins of the user by 1
_load_user ( $username ) : object Loads the user object from database using username
_reset_failed_attempts ( $user ) : void Reset the number of failed login attempts
_save_user ( $user ) : void Saves the user object
_set_last_attempt ( $user ) : void Sets the last attempt field of the user object to current time
_set_last_login ( $user ) : void Sets the last login field of the user object to current time
find_user ( ) : object Finds the user in the session (if any)

Описание методов

__construct() защищенный Метод

Loads Session and configuration options.
protected __construct ( $_name = 'a1', $_config ) : void
Результат void

_get_failed_attempts() защищенный Метод

Returns the number of failed login attempts
protected _get_failed_attempts ( $user ) : void
Результат void

_increment_failed_attempts() защищенный Метод

Increment the number of failed login attempts since last successfull login
protected _increment_failed_attempts ( $user ) : void
Результат void

_increment_logins() защищенный Метод

Increment the number of logins of the user by 1
protected _increment_logins ( $user ) : void
Результат void

_load_user() абстрактный защищенный Метод

Loads the user object from database using username
abstract protected _load_user ( $username ) : object
Результат object User Object

_reset_failed_attempts() защищенный Метод

Reset the number of failed login attempts
protected _reset_failed_attempts ( $user ) : void
Результат void

_save_user() защищенный Метод

Saves the user object
protected _save_user ( $user ) : void
Результат void

_set_last_attempt() защищенный Метод

Sets the last attempt field of the user object to current time
protected _set_last_attempt ( $user ) : void
Результат void

_set_last_login() защищенный Метод

Sets the last login field of the user object to current time
protected _set_last_login ( $user ) : void
Результат void

check() публичный Метод

Checks if password matches hash
public check ( $password, $hash ) : boolean
Результат boolean password matches hashed password

check_password() публичный Метод

if ( $a1->check_password($user, $this->request->post('password'))) { delete account or some other special action }
public check_password ( $user, $password ) : boolean
Результат boolean Success

complete_login() публичный Метод

Updates session, set remember cookie (if required)
public complete_login ( $user, $remember = FALSE ) : TRUE
Результат TRUE

failed_login() публичный Метод

Registers a failed login attempt
public failed_login ( $user ) : FALSE
Результат FALSE

find_user() защищенный Метод

Finds the user in the session (if any)
protected find_user ( ) : object
Результат object / FALSE

get_user() публичный Метод

Returns the user - if any
public get_user ( ) : object
Результат object / FALSE

hash() публичный Метод

Generates bcrypt hash for input
public hash ( $input, $salt = NULL, $cost = NULL ) : string
Результат string hashed input value

instance() публичный статический Метод

Return a static instance of A1.
public static instance ( $_name = 'a1' ) : object
Результат object

logged_in() публичный Метод

Returns TRUE is a user is currently logged in
public logged_in ( ) : boolean
Результат boolean

login() публичный Метод

Attempt to log in a user.
public login ( $username, $password, $remember = FALSE ) : mixed
Результат mixed user if succesfull, FALSE otherwise

logout() публичный Метод

Log out a user by removing the related session variables.
public logout ( $destroy = FALSE ) : boolean
Результат boolean

session() публичный Метод

(Initializes &) Returns the session we're working with
public session ( $id = NULL ) : Session
Результат Session

set_user() публичный Метод

Sets the user that is logged in
public set_user ( $user ) : object
Результат object / FALSE

store_user_in_session() публичный Метод

Stores user model in session
public store_user_in_session ( $user ) : void
Результат void

Описание свойств

$_config защищенное свойство

protected $_config

$_name защищенное свойство

protected $_name

$_sess защищенное свойство

protected $_sess

$_user защищенное свойство

protected $_user