PHP Класс Phpauth\Auth

Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$config
$lang

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

Свойство Тип Описание
$dbh

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

Метод Описание
__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.

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

Метод Описание
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

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

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

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

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

Activates a user's account
public activate ( string $key ) : array
$key string
Результат array $return

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

Adds an attempt to database
protected addAttempt ( ) : boolean
Результат boolean

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

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
Результат boolean

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

Creates a session for a specified user id
protected addSession ( integer $uid, boolean $remember ) : array
$uid integer
$remember boolean
Результат array $data

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

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
Результат integer $uid

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

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
Результат array $return

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

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
Результат array $return

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

Verifies a captcha code
protected checkCaptcha ( string $captcha ) : boolean
$captcha string
Результат boolean

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

Function to check if a session is valid
public checkSession ( string $hash ) : boolean
$hash string
Результат boolean

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

Compare user's password with given password
public comparePasswords ( integer $userid, string $password_for_check ) : boolean
$userid integer
$password_for_check string
Результат boolean

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

Deletes all attempts for a given IP from database
protected deleteAttempts ( string $ip, boolean $all = false ) : boolean
$ip string
$all boolean = false
Результат boolean

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

Removes all existing sessions for a given UID
protected deleteExistingSessions ( integer $uid ) : boolean
$uid integer
Результат boolean

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

Deletes request from database
protected deleteRequest ( integer $id ) : boolean
$id integer
Результат boolean

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

Removes a session based on hash
protected deleteSession ( string $hash ) : boolean
$hash string
Результат boolean

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

Allows a user to delete their account
public deleteUser ( integer $uid, string $password, string $captcha = NULL ) : array
$uid integer
$password string
$captcha string = NULL
Результат array $return

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

Gets basic user data for a given UID and returns an array
protected getBaseUser ( integer $uid ) : array
$uid integer
Результат array $data

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

Hashes provided password with Bcrypt
public getHash ( string $password ) : string
$password string
Результат string

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

Returns IP address
protected getIp ( ) : string
Результат string $ip

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

Returns a random string of a specified length
public getRandomKey ( integer $length = 20 ) : string
$length integer
Результат string $key

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

Returns request data if key is valid
public getRequest ( string $key, string $type ) : array
$key string
$type string
Результат array $return

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

Returns current session hash
public getSessionHash ( ) : string
Результат string

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

Retrieves the UID associated with a given session hash
public getSessionUID ( string $hash ) : integer
$hash string
Результат integer $uid

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

Gets UID for a given email address and returns an array
public getUID ( string $email ) : array
$email string
Результат array $uid

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

Gets public user data for a given UID and returns an array, password is not returned
public getUser ( integer $uid ) : array
$uid integer
Результат array $data

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

Informs if a user is locked out
public isBlocked ( ) : string
Результат string

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

Checks if an email is already in use
public isEmailTaken ( string $email ) : boolean
$email string
Результат boolean

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

Returns is user logged in
public isLogged ( ) : boolean
Результат boolean

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

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
Результат array $return

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

Logs out the session, identified by hash
public logout ( string $hash ) : boolean
$hash string
Результат boolean

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

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
Результат array $return

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

Creates a reset key for an email address and sends email
public requestReset ( string $email, $sendmail = NULL ) : array
$email string
Результат array $return

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

Recreates activation email for a given email and sends
public resendActivation ( string $email, $sendmail = NULL ) : array
$email string
Результат array $return

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

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
Результат array $return

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

Verifies that an email is valid
protected validateEmail ( string $email ) : array
$email string
Результат array $return

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

Verifies that a password is valid and respects security requirements
protected validatePassword ( string $password ) : array
$password string
Результат array $return

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

$config публичное свойство

public $config

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

protected $dbh

$lang публичное свойство

public $lang