\Horde_Token_File

Token tracking implementation for local files.

Copyright 1999-2017 Horde LLC (http://www.horde.org/)

See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.

Summary

Methods
Properties
Constants
__construct()
verify()
exists()
add()
purge()
get()
isValid()
validate()
validateUnique()
getNonce()
__destruct()
No public properties found
FILE_PREFIX
_encodeRemoteAddress()
_connect()
_disconnect()
$_params
$_fd
$_connected
N/A
_decode()
_isExpired()
_hash()
No private properties found
N/A

Constants

FILE_PREFIX

FILE_PREFIX

Properties

$_params

$_params : array

Hash of parameters necessary to use the chosen backend.

Type

array

$_fd

$_fd : resource

Handle for the open file descriptor.

Type

resource

$_connected

$_connected : boolean

Boolean indicating whether or not we have an open file descriptor.

Type

boolean

Methods

__construct()

__construct(array  $params = array()) 

Constructor.

Parameters

array $params

Optional parameters:

  • token_dir (string): The directory where to keep token files. DEFAULT: System temporary directory

verify()

verify(string  $token) : boolean

Checks if the given token has been previously used. First purges all expired tokens. Then retrieves current tokens for the given ip address. If the specified token was not found, adds it.

Parameters

string $token

The value of the token to check.

Throws

\Horde_Token_Exception

Returns

boolean —

True if the token has not been used, false otherwise.

exists()

exists(string  $tokenID) : boolean

Does the token exist?

Parameters

string $tokenID

Token ID.

Throws

\Horde_Token_Exception

Returns

boolean —

True if the token exists.

add()

add(string  $tokenID) 

Add a token ID.

Parameters

string $tokenID

Token ID to add.

Throws

\Horde_Token_Exception

purge()

purge() 

Delete all expired connection IDs.

Throws

\Horde_Token_Exception

get()

get(string  $seed = '') : string

Return a new signed token.

Parameters

string $seed

A unique ID to be included in the token.

Returns

string —

The new token.

isValid()

isValid(string  $token, string  $seed = '', integer  $timeout = null, boolean  $unique = false) : boolean

Validate a signed token.

Parameters

string $token

The signed token.

string $seed

The unique ID of the token.

integer $timeout

Timout of the token in seconds. Values below zero represent no timeout.

boolean $unique

Should validation of the token succeed only once?

Returns

boolean —

True if the token was valid.

validate()

validate(string  $token, string  $seed = '', integer  $timeout = null) : array

Is the given token still valid? Throws an exception in case it is not.

Parameters

string $token

The signed token.

string $seed

The unique ID of the token.

integer $timeout

Timout of the token in seconds. Values below zero represent no timeout.

Throws

\Horde_Token_Exception

If the token was invalid.

Returns

array —

An array of two elements: The nonce and the hash.

validateUnique()

validateUnique(string  $token, string  $seed = '') : NULL

Is the given token valid and has never been used before? Throws an exception otherwise.

Parameters

string $token

The signed token.

string $seed

The unique ID of the token.

Throws

\Horde_Token_Exception

If the token was invalid or has been used before.

Returns

NULL

getNonce()

getNonce() : string

Return a "number used once" (a concatenation of a timestamp and a random numer).

Returns

string —

A string of 6 bytes.

__destruct()

__destruct() 

Destructor.

_encodeRemoteAddress()

_encodeRemoteAddress() : string

Encodes the remote address.

Returns

string —

Encoded address.

_connect()

_connect() 

Opens a file descriptor to a new or existing file.

Throws

\Horde_Token_Exception

_disconnect()

_disconnect(boolean  $error = true) 

Closes the file descriptor.

Parameters

boolean $error

Throw exception on error?

Throws

\Horde_Token_Exception

_decode()

_decode(string  $token) : array

Decode a token into the prefixed nonce and the hash.

Parameters

string $token

The token to be decomposed.

Returns

array —

An array of two elements: The nonce and the hash.

_isExpired()

_isExpired(string  $nonce, integer  $timeout) : boolean

Has the nonce expired?

Parameters

string $nonce

The to be checked for expiration.

integer $timeout

The timeout that should be applied.

Returns

boolean —

True if the nonce expired.

_hash()

_hash(string  $text) : string

Sign the given text with the secret.

Parameters

string $text

The text to be signed.

Returns

string —

The hashed text.