class Accounts (View source)

The Accounts class provides all methods for creating and loading user accounts.

Methods

static array
add()

Add user account based on $_POST.

static array
delete(array $users)

Delete one ore more user accounts.

static string
install()

Install the first user account.

static string
generatePHP(array $accounts)

Generate the PHP code for the accounts file. Basically the code returns the unserialized serialized array with all users.

static array
get()

Get the accounts array by including the accounts PHP file.

static string
passwordHash(string $password)

Create hash from password to store in accounts.txt.

static boolean
passwordVerified(string $password, string $hash)

Verify if a password matches its hashed version.

static boolean
write($accounts)

Save the accounts array as PHP to AM_FILE_ACCOUNTS.

Details

static array add()

Add user account based on $_POST.

Return Value

array $output (error/success)

static array delete(array $users)

Delete one ore more user accounts.

Parameters

array $users

Return Value

array $output (error/success)

static string install()

Install the first user account.

Return Value

string Error message in case of an error.

static string generatePHP(array $accounts)

Generate the PHP code for the accounts file. Basically the code returns the unserialized serialized array with all users.

That way, the accounts array can be stored as PHP. The accounts file has to be a PHP file for security reasons. When trying to access the file directly via the browser, it gets executed instead of revealing any user names.

Parameters

array $accounts

Return Value

string The PHP code

static array get()

Get the accounts array by including the accounts PHP file.

Return Value

array The registered accounts

static string passwordHash(string $password)

Create hash from password to store in accounts.txt.

Parameters

string $password

Return Value

string Hashed/salted password

static boolean passwordVerified(string $password, string $hash)

Verify if a password matches its hashed version.

Parameters

string $password (clear text)
string $hash (hashed password)

Return Value

boolean true/false

static boolean write($accounts)

Save the accounts array as PHP to AM_FILE_ACCOUNTS.

Parameters

$accounts

Return Value

boolean Success (true/false)