Authentication

Authenticate users in an application with fewer lines of code by using Simcify authentication class.

This class is bundled with all the necessary functions needed for authentication.

  • Login

  • Registration

  • Remember Me

  • Forgot password

  • reset Passord

  • Session Storage

  • Log out

Authentication is handled by the Simcify\Auth class. The core methods are described below:

void Auth::authenticate( \stdclass $user [, boolean $remember = false ])

Authenticates a user after email/username - password verification is done and sets a remember cookie on request.

Parameters

Type

Required

Default

Description

$user

\stdclass

Yes

none

A \stdclass representation of a user from the database with at least the 'id' property

$remember

boolean

No

false

If set to true, a remember cookie is set for the user.

Returns void

boolean Auth::check()

Gets the authentication state of the current user.

Returns boolean - true if authenticated false if not

void Auth::deauthenticate()

Revokes the current user's authentication and deletes any remember cookies.

Returns void

string Auth::password( string $str )

Creates a sha256 hashed value of the string passed using PHP's hmac_hash function salted with the application's secret key.

Parameters

Type

Required

Default

Description

$str

string

Yes

none

The string to hash

Returns string - A hashed value of the input string.

void Auth:remember()

Authenticates a user using their remember cookie without the need to prompt them for a username and password. NOTE: The user must have enabled cookies on their browser for this to work correctly. Remember to follow GDPR guidelines on cookies.

Returns void

\stdclass Auth::user()

Retrieves the authenticated user from the database with all fields included. NOTE: The ->password field is already hashed.

Returns \stdclass - A standard PHP object with the user's database fields as properties.