User Guide | Validation Functions

The flexi auth library functions to validate user credentials and data integrity.

Validation Functions

Validation Index | Validation / Security Config

Help with Function Parameters

Show / Hide Help

Name: The name of the function parameter (argument).

Data Type: The data type that is expected by the parameter.

  • bool : Requires a boolean value of 'TRUE' or 'FALSE'.
  • string : Requires a textual value.
  • int : Requires a numeric value. It does not matter whether the value is an integer, float, decimal etc.
  • array : Requires an array.

Required: Defines whether the parameter requires a value to be submitted.

Default: Defines the default parameter value that is used if no other value is submitted.

is_logged_in()

Verifies a user is logged in either via entering a valid password or using the 'Remember me' feature.


Library and Requirements

Available via the lite and standard libraries.

How it Works

The function checks a value saved in the users browser session.

Return Values

Failure:FALSE

Success:TRUE

Example
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
is_logged_in() Is the current user logged in? bool(false)

is_logged_in_via_password()

Verifies a user has logged in via entering a valid password rather than using the 'Remember me' feature (Login by password is more secure).


Library and Requirements

Available via the lite and standard libraries.

How it Works

The function checks a value saved in the users browser session.

Return Values

Failure:FALSE

Success:TRUE

Example
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
is_logged_in_via_password() Is the current user logged in via entering a password (Rather than a 'Remember me' cookie)? bool(false)

is_admin()

Verifies a user belongs to a user group with admin permissions.


Library and Requirements

Available via the lite and standard libraries.

How it Works

The function checks a value saved in the users browser session.

Return Values

Failure:FALSE

Success:TRUE

Example
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
is_admin() Is the current user logged in with admin credentials? bool(false)

in_group()

Verifies whether a user is assigned to a particular user group.


Library and Requirements

Available via the lite and standard libraries standard library.

Function Parameters
in_group(groups) Help
Name Data Type Required Default Description
groups int | string | array Yes FALSE Defines which user group(s) to check for whether the currently logged in user is assigned to.
The user group id or name can be checked, or alternatively an array of ids or names can be defined to check multiple groups.
How it Works

The function checks a value saved in the users browser session.

Return Values

Failure:FALSE

Success:TRUE

Examples
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
in_group('moderator') Is the current logged in user assigned to the 'Moderator' user group? bool(false)
in_group(array('moderator', 'editor')) Is the current logged in user assigned to either the 'Moderator' or 'Editor' user groups? bool(false)

is_privileged()

Verifies whether a user has a specific privilege.


Library and Requirements

Available via the lite and standard libraries.

Function Parameters
is_privileged(privileges) Help
Name Data Type Required Default Description
privileges int | string | array Yes FALSE Defines which user privilege(s) to check for whether the currently logged in user is assigned to.
The user privilege id or name can be checked, or alternatively an array of ids or names can be defined to check multiple privileges.
How it Works

The function checks a value saved in the users browser session.

Return Values

Failure:FALSE

Success:TRUE

Example
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
is_privileged('Update Users') Does the current logged in user have the privilege to 'Update Users'? bool(false)
is_privileged(array('Update Users', 'Delete Users')) Does the current logged in user have the privilege to either 'Update Users' or 'Delete Users'? bool(false)

identity_available()

Returns whether a user identity (Username and/or Email) is available.


Library and Requirements

Available via the standard library.

Function Parameters
identity_available(identity, user_id) Help
Name Data Type Required Default Description
identity string Yes FALSE The identity (Username and/or Email) to be checked.
user_id int No FALSE Defines the id of a user to be excluded from the identity check.
The purpose of this is to exclude the user that currently has the submitted identity value set as their current identity.
For example, if a user updates their account details, but their email address remains unchanged, without the user id being excluded from the identity check, the users own identity would be matched, indicating that the identity was unavailable.
How it Works

The function checks the defined identity columns in the user database table trying to match any other users that already have the submitted identity as their own identity.

If a user id is submitted, the function will exclude that user from the query to prevent their own identity conflicting with the query result.

Notes

The identity columns are defined via the 'identity_cols' variable in the config. file.

Return Values

Failure:FALSE

Success:TRUE

Examples
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
identity_available('admin@admin.com') Is the email address 'admin@admin.com' currently available? bool(false)
identity_available('available_identity') Is the username 'available_identity' currently available? bool(true)
identity_available('admin@admin.com', 1) Is the email address 'admin@admin.com' currently available whilst excluding the user with an id of '1'? bool(true)
identity_available('admin@admin.com', 2) Is the email address 'admin@admin.com' currently available whilst excluding the user with an id of '2'? bool(false)

email_available()

Returns whether an email address is available.


Library and Requirements

Available via the standard library.

Function Parameters
email_available(email, user_id) Help
Name Data Type Required Default Description
email string Yes FALSE The email address to be checked.
user_id int No FALSE Defines the id of a user to be excluded from the email check.
The purpose of this is to exclude the user that currently has the submitted email value set as their current email address.
For example, if a user updates their account details, but their email address remains unchanged, without the user id being excluded from the email check, the users own email would be matched, indicating that the email was unavailable.
How it Works

The function checks the email column in the user database table trying to match any other users that already have the submitted email as their own email address.

If a user id is submitted, the function will exclude that user from the query to prevent their own email conflicting with the query result.

Return Values

Failure:FALSE

Success:TRUE

Examples
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
email_available('admin@admin.com') Is the email address 'admin@admin.com' currently available? bool(false)
email_available('available@available.com') Is the email address 'available@available.com' currently available? bool(true)
email_available('admin@admin.com', 1) Is the email address 'admin@admin.com' currently available whilst excluding the user with an id of '1'? bool(true)
email_available('admin@admin.com', 2) Is the email address 'admin@admin.com' currently available whilst excluding the user with an id of '2'? bool(false)

username_available()

Returns whether a username is available.


Library and Requirements

Available via the standard library.

Function Parameters
username_available(username, user_id) Help
Name Data Type Required Default Description
username string Yes FALSE The username to be checked.
user_id int No FALSE Defines the id of a user to be excluded from the username check.
The purpose of this is to exclude the user that currently has the submitted username value set as their current username.
For example, if a user updates their account details, but their username remains unchanged, without the user id being excluded from the username check, the users own username would be matched, indicating that the username was unavailable.
How it Works

The function checks the username column in the user database table trying to match any other users that already have the submitted username as their own username.

If a user id is submitted, the function will exclude that user from the query to prevent their own username conflicting with the query result.

Return Values

Failure:FALSE

Success:TRUE

Examples
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
username_available('admin') Is the username 'admin' currently available? bool(false)
username_available('available_username') Is the username 'available_username' currently available? bool(true)
username_available('admin@admin.com', 1) Is the username 'admin@admin.com' currently available whilst excluding the user with an id of '1'? bool(true)
username_available('admin@admin.com', 2) Is the username 'admin@admin.com' currently available whilst excluding the user with an id of '2'? bool(true)

validate_current_password()

Validate a submitted password matches the password of a specific user stored in the database.


Library and Requirements

Available via the standard library.

How it Works

The function compares a submitted password against the users current password saved within the database.

Return Values

Failure:FALSE

Success:TRUE

Example
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
validate_current_password('password123', 'admin@admin.com') Is 'admin@admin.com' current password 'password123'? bool(true)
validate_current_password('WRONGPASSWORD', 'admin@admin.com') Is 'admin@admin.com' current password 'WRONGPASSWORD'? bool(false)

min_password_length()

Gets the minimum valid password character length.


Library and Requirements

Available via the standard library.

How it Works

The function returns the minimum password length defined via the config. file.

Return Values

Failure:n/a

Success:int

Example
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
min_password_length() What is the minimum password length defined via the config. file? 8

valid_password_chars()

Validate whether the submitted password only contains valid characters.


Library and Requirements

Available via the standard library.

Function Parameters
valid_password_chars(password) Help
Name Data Type Required Default Description
password string Yes FALSE Defines the password to be validated.
How it Works

The function compares the submitted password against the 'valid_password_chars' regex string defined via the config. file.

Return Values

Failure:FALSE

Success:TRUE

Examples
Note: The returned example values below are displaying live data from the current auth database and session data set via the demo.
valid_password_chars('password123') The the password string 'password123' contain valid characters? bool(true)
valid_password_chars('@password#123') The the password string '@password#123' contain valid characters? bool(false)