PHP Class 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
Afficher le fichier Open project: wouterrr/a1

Protected Properties

Свойство Type Description
$_config
$_name
$_sess
$_user

Méthodes publiques

Méthode Description
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

Méthodes protégées

Méthode Description
__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)

Method Details

__construct() protected méthode

Loads Session and configuration options.
protected __construct ( $_name = 'a1', $_config ) : void
Résultat void

_get_failed_attempts() protected méthode

Returns the number of failed login attempts
protected _get_failed_attempts ( $user ) : void
Résultat void

_increment_failed_attempts() protected méthode

Increment the number of failed login attempts since last successfull login
protected _increment_failed_attempts ( $user ) : void
Résultat void

_increment_logins() protected méthode

Increment the number of logins of the user by 1
protected _increment_logins ( $user ) : void
Résultat void

_load_user() abstract protected méthode

Loads the user object from database using username
abstract protected _load_user ( $username ) : object
Résultat object User Object

_reset_failed_attempts() protected méthode

Reset the number of failed login attempts
protected _reset_failed_attempts ( $user ) : void
Résultat void

_save_user() protected méthode

Saves the user object
protected _save_user ( $user ) : void
Résultat void

_set_last_attempt() protected méthode

Sets the last attempt field of the user object to current time
protected _set_last_attempt ( $user ) : void
Résultat void

_set_last_login() protected méthode

Sets the last login field of the user object to current time
protected _set_last_login ( $user ) : void
Résultat void

check() public méthode

Checks if password matches hash
public check ( $password, $hash ) : boolean
Résultat boolean password matches hashed password

check_password() public méthode

if ( $a1->check_password($user, $this->request->post('password'))) { delete account or some other special action }
public check_password ( $user, $password ) : boolean
Résultat boolean Success

complete_login() public méthode

Updates session, set remember cookie (if required)
public complete_login ( $user, $remember = FALSE ) : TRUE
Résultat TRUE

failed_login() public méthode

Registers a failed login attempt
public failed_login ( $user ) : FALSE
Résultat FALSE

find_user() protected méthode

Finds the user in the session (if any)
protected find_user ( ) : object
Résultat object / FALSE

get_user() public méthode

Returns the user - if any
public get_user ( ) : object
Résultat object / FALSE

hash() public méthode

Generates bcrypt hash for input
public hash ( $input, $salt = NULL, $cost = NULL ) : string
Résultat string hashed input value

instance() public static méthode

Return a static instance of A1.
public static instance ( $_name = 'a1' ) : object
Résultat object

logged_in() public méthode

Returns TRUE is a user is currently logged in
public logged_in ( ) : boolean
Résultat boolean

login() public méthode

Attempt to log in a user.
public login ( $username, $password, $remember = FALSE ) : mixed
Résultat mixed user if succesfull, FALSE otherwise

logout() public méthode

Log out a user by removing the related session variables.
public logout ( $destroy = FALSE ) : boolean
Résultat boolean

session() public méthode

(Initializes &) Returns the session we're working with
public session ( $id = NULL ) : Session
Résultat Session

set_user() public méthode

Sets the user that is logged in
public set_user ( $user ) : object
Résultat object / FALSE

store_user_in_session() public méthode

Stores user model in session
public store_user_in_session ( $user ) : void
Résultat void

Property Details

$_config protected_oe property

protected $_config

$_name protected_oe property

protected $_name

$_sess protected_oe property

protected $_sess

$_user protected_oe property

protected $_user