PHP Class Phpauth\Auth

Datei anzeigen Open project: phpauth/phpauth

Public Properties

Property Type Description
$config
$lang

Protected Properties

Property Type Description
$dbh

Public Methods

Method Description
__construct ( PDO $dbh, $config, $language = "en_GB" ) Initiates database connection
activate ( string $key ) : array Activates a user's account
changeEmail ( integer $uid, string $email, string $password, string $captcha = NULL ) : array Changes a user's email
changePassword ( integer $uid, string $currpass, string $newpass, string $repeatnewpass, string $captcha = NULL ) : array Changes a user's password
checkSession ( string $hash ) : boolean Function to check if a session is valid
comparePasswords ( integer $userid, string $password_for_check ) : boolean Compare user's password with given password
deleteUser ( integer $uid, string $password, string $captcha = NULL ) : array Allows a user to delete their account
getHash ( string $password ) : string Hashes provided password with Bcrypt
getRandomKey ( integer $length = 20 ) : string Returns a random string of a specified length
getRequest ( string $key, string $type ) : array Returns request data if key is valid
getSessionHash ( ) : string Returns current session hash
getSessionUID ( string $hash ) : integer Retrieves the UID associated with a given session hash
getUID ( string $email ) : array Gets UID for a given email address and returns an array
getUser ( integer $uid ) : array Gets public user data for a given UID and returns an array, password is not returned
isBlocked ( ) : string Informs if a user is locked out
isEmailTaken ( string $email ) : boolean Checks if an email is already in use
isLogged ( ) : boolean Returns is user logged in
login ( string $email, string $password, integer $remember, string $captcha = NULL ) : array Logs a user in
logout ( string $hash ) : boolean Logs out the session, identified by hash
register ( string $email, string $password, string $repeatpassword, array $params = [], string $captcha = NULL, boolean $sendmail = NULL ) : array Creates a new user, adds them to database
requestReset ( string $email, $sendmail = NULL ) : array Creates a reset key for an email address and sends email
resendActivation ( string $email, $sendmail = NULL ) : array Recreates activation email for a given email and sends
resetPass ( string $key, string $password, string $repeatpassword, string $captcha = NULL ) : array Allows a user to reset their password after requesting a reset key.

Protected Methods

Method Description
addAttempt ( ) : boolean Adds an attempt to database
addRequest ( integer $uid, string $email, string $type, boolean &$sendmail ) : boolean Creates an activation entry and sends email to user
addSession ( integer $uid, boolean $remember ) : array Creates a session for a specified user id
addUser ( string $email, string $password, array $params = [], &$sendmail ) : integer Adds a new user to database
checkCaptcha ( string $captcha ) : boolean Verifies a captcha code
deleteAttempts ( string $ip, boolean $all = false ) : boolean Deletes all attempts for a given IP from database
deleteExistingSessions ( integer $uid ) : boolean Removes all existing sessions for a given UID
deleteRequest ( integer $id ) : boolean Deletes request from database
deleteSession ( string $hash ) : boolean Removes a session based on hash
getBaseUser ( integer $uid ) : array Gets basic user data for a given UID and returns an array
getIp ( ) : string Returns IP address
validateEmail ( string $email ) : array Verifies that an email is valid
validatePassword ( string $password ) : array Verifies that a password is valid and respects security requirements

Method Details

__construct() public method

Initiates database connection
public __construct ( PDO $dbh, $config, $language = "en_GB" )
$dbh PDO

activate() public method

Activates a user's account
public activate ( string $key ) : array
$key string
return array $return

addAttempt() protected method

Adds an attempt to database
protected addAttempt ( ) : boolean
return boolean

addRequest() protected method

Creates an activation entry and sends email to user
protected addRequest ( integer $uid, string $email, string $type, boolean &$sendmail ) : boolean
$uid integer
$email string
$type string
$sendmail boolean = NULL
return boolean

addSession() protected method

Creates a session for a specified user id
protected addSession ( integer $uid, boolean $remember ) : array
$uid integer
$remember boolean
return array $data

addUser() protected method

Adds a new user to database
protected addUser ( string $email, string $password, array $params = [], &$sendmail ) : integer
$email string -- email
$password string -- password
$params array -- additional params
return integer $uid

changeEmail() public method

Changes a user's email
public changeEmail ( integer $uid, string $email, string $password, string $captcha = NULL ) : array
$uid integer
$email string
$password string
$captcha string = NULL
return array $return

changePassword() public method

Changes a user's password
public changePassword ( integer $uid, string $currpass, string $newpass, string $repeatnewpass, string $captcha = NULL ) : array
$uid integer
$currpass string
$newpass string
$repeatnewpass string
$captcha string = NULL
return array $return

checkCaptcha() protected method

Verifies a captcha code
protected checkCaptcha ( string $captcha ) : boolean
$captcha string
return boolean

checkSession() public method

Function to check if a session is valid
public checkSession ( string $hash ) : boolean
$hash string
return boolean

comparePasswords() public method

Compare user's password with given password
public comparePasswords ( integer $userid, string $password_for_check ) : boolean
$userid integer
$password_for_check string
return boolean

deleteAttempts() protected method

Deletes all attempts for a given IP from database
protected deleteAttempts ( string $ip, boolean $all = false ) : boolean
$ip string
$all boolean = false
return boolean

deleteExistingSessions() protected method

Removes all existing sessions for a given UID
protected deleteExistingSessions ( integer $uid ) : boolean
$uid integer
return boolean

deleteRequest() protected method

Deletes request from database
protected deleteRequest ( integer $id ) : boolean
$id integer
return boolean

deleteSession() protected method

Removes a session based on hash
protected deleteSession ( string $hash ) : boolean
$hash string
return boolean

deleteUser() public method

Allows a user to delete their account
public deleteUser ( integer $uid, string $password, string $captcha = NULL ) : array
$uid integer
$password string
$captcha string = NULL
return array $return

getBaseUser() protected method

Gets basic user data for a given UID and returns an array
protected getBaseUser ( integer $uid ) : array
$uid integer
return array $data

getHash() public method

Hashes provided password with Bcrypt
public getHash ( string $password ) : string
$password string
return string

getIp() protected method

Returns IP address
protected getIp ( ) : string
return string $ip

getRandomKey() public method

Returns a random string of a specified length
public getRandomKey ( integer $length = 20 ) : string
$length integer
return string $key

getRequest() public method

Returns request data if key is valid
public getRequest ( string $key, string $type ) : array
$key string
$type string
return array $return

getSessionHash() public method

Returns current session hash
public getSessionHash ( ) : string
return string

getSessionUID() public method

Retrieves the UID associated with a given session hash
public getSessionUID ( string $hash ) : integer
$hash string
return integer $uid

getUID() public method

Gets UID for a given email address and returns an array
public getUID ( string $email ) : array
$email string
return array $uid

getUser() public method

Gets public user data for a given UID and returns an array, password is not returned
public getUser ( integer $uid ) : array
$uid integer
return array $data

isBlocked() public method

Informs if a user is locked out
public isBlocked ( ) : string
return string

isEmailTaken() public method

Checks if an email is already in use
public isEmailTaken ( string $email ) : boolean
$email string
return boolean

isLogged() public method

Returns is user logged in
public isLogged ( ) : boolean
return boolean

login() public method

Logs a user in
public login ( string $email, string $password, integer $remember, string $captcha = NULL ) : array
$email string
$password string
$remember integer
$captcha string = NULL
return array $return

logout() public method

Logs out the session, identified by hash
public logout ( string $hash ) : boolean
$hash string
return boolean

register() public method

Creates a new user, adds them to database
public register ( string $email, string $password, string $repeatpassword, array $params = [], string $captcha = NULL, boolean $sendmail = NULL ) : array
$email string
$password string
$repeatpassword string
$params array
$captcha string = NULL
$sendmail boolean = NULL
return array $return

requestReset() public method

Creates a reset key for an email address and sends email
public requestReset ( string $email, $sendmail = NULL ) : array
$email string
return array $return

resendActivation() public method

Recreates activation email for a given email and sends
public resendActivation ( string $email, $sendmail = NULL ) : array
$email string
return array $return

resetPass() public method

Allows a user to reset their password after requesting a reset key.
public resetPass ( string $key, string $password, string $repeatpassword, string $captcha = NULL ) : array
$key string
$password string
$repeatpassword string
$captcha string = NULL
return array $return

validateEmail() protected method

Verifies that an email is valid
protected validateEmail ( string $email ) : array
$email string
return array $return

validatePassword() protected method

Verifies that a password is valid and respects security requirements
protected validatePassword ( string $password ) : array
$password string
return array $return

Property Details

$config public_oe property

public $config

$dbh protected_oe property

protected $dbh

$lang public_oe property

public $lang