Control and count clicks.

Typically used by log in forms to prevent brute force attacks. For example, can count user log in attempts and script can then lock the form for a period of time if they fail to use correct credentials within that limit.

package dstruct_auth

 Methods

Class constructor.

__construct() 

Attempts to grab the default cache object and will set an identifier for the user (session or the IP).

see \Prefs::CLICK_CONTROL_IDENTIFIER_IS_SESSION

Exceptions

\DStructGeneralException If can not find 'global' cache

Check to see whether the user is allowed to attempt a click.

allowClick(string $userkey) : boolean

See if click can be authorised by the current click count being a lower value than the allowed clicks set and the current timestamp being less than the timestamp stored in the cache under the current object key, returning true or false.

Parameters

$userkey

string

Key used to identify the clickable object in the script

Returns

boolean

Delete the cache entry.

clear(string $userkey) 

This will have the effect of resetting the clicks etc.

Parameters

$userkey

string

Key used to identify the clickable object in the script

Record a click.

click(string $userkey) 

Parameters

$userkey

string

Key used to identify the clickable object in the script

Return the number of clicks stored in the cache.

getClickCount(string $userkey) : integer

Parameters

$userkey

string

Key used to identify the clickable object in the script

Returns

integer

Return the UTS value that has been set.

getTimeOut() : integer

Is the time between the web users final allowed click before access is granted to click again

see \setTimeOut()

Returns

integer

Return the time in UTS of the last attempt which was stored in the cache.

getTimestamp(string $userkey) : mixed

Parameters

$userkey

string

Key used to identify the clickable object in the script

Returns

mixedInteger or false

Sets the TimeOut in UTS.

setTimeOut(integer $timeout) 

TimeOut to block access to a web user once the number of click attempts matches the number of allowed clicks set.

Parameters

$timeout

integer

Return the key to be stored in the cache.

getKey(string $userkey) : string

The key that is used in the cache is a concatenation of the application name (Prefs::APP_NAME), the $userkey and the identifier (either the session or the IP).

Parameters

$userkey

string

Key used to identify the clickable object in the script

Returns

string

 Properties

 

$cache : object
 

$clickcount : integer
 

$timeout : integer

In seconds. Default is 172800 - two days.

 

$ttl : integer

In seconds. Default is 173100 - two days, five minutes. The entry in the cache will be invalidated at this time - essentially five minutes after the $timeout as it is no longer needed.

 

$useridentifier : string