Security
in package
Functions for implementing security, including secure random numbers
Table of Contents
Constants
- PASSWORD_BCRYPT : mixed = PASSWORD_BCRYPT
- PASSWORD_BCRYPT12 : mixed = 3
- PASSWORD_DEFAULT : mixed = PASSWORD_DEFAULT
- Password algorithms
- PASSWORD_PLAIN : mixed = 4
- PASSWORD_SHA : mixed = 1
- PASSWORD_SHA_SALT : mixed = 2
- PASSWORD_SHA_SALT_5000 : mixed = 5
Methods
- compareStrings() : bool
- Constant-time string comparison
- doPasswordCheck() : bool
- Check a password hash against an entered password
- hashPassword() : array<string|int, mixed>
- Return a hashed password, password algorithm, and salt, for inserting into the database
- randByte() : string
- Return a single random byte
- randBytes() : string
- Returns a binary string of random bytes
- randStr() : string
- Returns a string of random characters
Constants
PASSWORD_BCRYPT
public
mixed
PASSWORD_BCRYPT
= PASSWORD_BCRYPT
PASSWORD_BCRYPT12
public
mixed
PASSWORD_BCRYPT12
= 3
PASSWORD_DEFAULT
Password algorithms
public
mixed
PASSWORD_DEFAULT
= PASSWORD_DEFAULT
PASSWORD_PLAIN
public
mixed
PASSWORD_PLAIN
= 4
PASSWORD_SHA
public
mixed
PASSWORD_SHA
= 1
PASSWORD_SHA_SALT
public
mixed
PASSWORD_SHA_SALT
= 2
PASSWORD_SHA_SALT_5000
public
mixed
PASSWORD_SHA_SALT_5000
= 5
Methods
compareStrings()
Constant-time string comparison
public
static compareStrings(string $known_string, string $user_string) : bool
Use hash_equals() instead.
Parameters
- $known_string : string
-
The known hash
- $user_string : string
-
The user supplied hash to check
Return values
bool —True if the strings match, false if they don't
doPasswordCheck()
Check a password hash against an entered password
public
static doPasswordCheck(string $known_hash, int|string $algorithm, string $salt, string $user_string) : bool
Use password_hash() instead.
Parameters
- $known_hash : string
-
The known hash to check against, typically from the database
- $algorithm : int|string
-
Password algorithm, self
- $salt : string
- $user_string : string
-
Password which was entered by the user, to check against the stored hash
Return values
bool —True if the password matches, false if it doesn't
hashPassword()
Return a hashed password, password algorithm, and salt, for inserting into the database
public
static hashPassword(string $password[, int|string $algorithm = self::PASSWORD_DEFAULT ]) : array<string|int, mixed>
Use password_hash() instead.
Parameters
- $password : string
-
Plaintext password
- $algorithm : int|string = self::PASSWORD_DEFAULT
Tags
Return values
array<string|int, mixed> —0 => hash, 1 => algorithm, 2 => salt
randByte()
Return a single random byte
public
static randByte() : string
Return values
string —Binary string; one byte
randBytes()
Returns a binary string of random bytes
public
static randBytes(int $length) : string
Parameters
- $length : int
Return values
string —Binary string
randStr()
Returns a string of random characters
public
static randStr([int $length = 16 ][, string $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890' ]) : string
Parameters
- $length : int = 16
- $chars : string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890'