Md5PasswordHash implements PasswordHashInterface
Class that implements MD5 salted hashing based on PHP's crypt() function.
MD5 salted hashing with PHP's crypt() should be available on most of the systems.
Table of Contents
Interfaces
- PasswordHashInterface
 - Interface with public methods needed to be implemented in a salting hashing class.
 
Constants
- PREFIX = '$1$'
 - Prefix for the password hash.
 
Methods
- checkPassword() : bool
 - Method checks if a given plaintext password is correct by comparing it with a given salted hashed password.
 - getHashedPassword() : string|null
 - Method creates a hash for a given plaintext password
 - isAvailable() : bool
 - Returns whether all prerequisites for the hashing methods are matched
 - isHashUpdateNeeded() : bool
 - Checks whether a user's hashed password needs to be replaced with a new hash.
 - isValidSaltedPW() : bool
 - Method determines if a given string is a valid salted hashed password.
 - applySettingsToSalt() : string
 - Method applies settings (prefix, suffix) to a salt.
 - base64Encode() : string
 - Encodes bytes into printable base 64 using the *nix standard from crypt().
 - getGeneratedSalt() : string
 - Generates a random base 64-encoded salt prefixed and suffixed with settings for the hash.
 - getItoa64() : string
 - Returns a string for mapping an int to the corresponding base 64 character.
 - getLengthBase64FromBytes() : int
 - Method determines required length of base64 characters for a given length of a byte string.
 - isValidSalt() : bool
 - Method determines if a given string is a valid salt
 
Constants
PREFIX
Prefix for the password hash.
    protected
        mixed
    PREFIX
    = '$1$'
    
    
    
    
Methods
checkPassword()
Method checks if a given plaintext password is correct by comparing it with a given salted hashed password.
    public
                    checkPassword(string $plainPW, string $saltedHashPW) : bool
    Parameters
- $plainPW : string
 - 
                    
plain-text password to compare with salted hash
 - $saltedHashPW : string
 - 
                    
salted hash to compare plain-text password with
 
Return values
bool —TRUE, if plain-text password matches the salted hash, otherwise FALSE
getHashedPassword()
Method creates a hash for a given plaintext password
    public
                    getHashedPassword(string $password) : string|null
    Parameters
- $password : string
 - 
                    
Plaintext password to create a hash from
 
Return values
string|null —Hashed password or null on empty password
isAvailable()
Returns whether all prerequisites for the hashing methods are matched
    public
                    isAvailable() : bool
    Return values
bool —Method available
isHashUpdateNeeded()
Checks whether a user's hashed password needs to be replaced with a new hash.
    public
                    isHashUpdateNeeded(string $passString) : bool
    This is typically called during the login process when the plain text password is available. A new hash is needed when the desired iteration count has changed through a change in the variable $hashCount or HASH_COUNT.
Parameters
- $passString : string
 - 
                    
Salted hash to check if it needs an update
 
Return values
bool —TRUE if salted hash needs an update, otherwise FALSE
isValidSaltedPW()
Method determines if a given string is a valid salted hashed password.
    public
                    isValidSaltedPW(string $saltedPW) : bool
    Parameters
- $saltedPW : string
 - 
                    
String to check
 
Return values
bool —TRUE if it's valid salted hashed password, otherwise FALSE
applySettingsToSalt()
Method applies settings (prefix, suffix) to a salt.
    protected
                    applySettingsToSalt(string $salt) : string
    Parameters
- $salt : string
 - 
                    
A salt to apply setting to
 
Return values
string —Salt with setting
base64Encode()
Encodes bytes into printable base 64 using the *nix standard from crypt().
    protected
                    base64Encode(string $input, int $count) : string
    Parameters
- $input : string
 - 
                    
The string containing bytes to encode.
 - $count : int
 - 
                    
The number of characters (bytes) to encode.
 
Return values
string —Encoded string
getGeneratedSalt()
Generates a random base 64-encoded salt prefixed and suffixed with settings for the hash.
    protected
                    getGeneratedSalt() : string
    Proper use of salts may defeat a number of attacks, including:
- The ability to try candidate passwords against multiple hashes at once.
 - The ability to use pre-hashed lists of candidate passwords.
 - The ability to determine whether two users have the same (or different) password without actually having to guess one of the passwords.
 
Return values
string —A character string containing settings and a random salt
getItoa64()
Returns a string for mapping an int to the corresponding base 64 character.
    protected
                    getItoa64() : string
    Return values
string —String for mapping an int to the corresponding base 64 character
getLengthBase64FromBytes()
Method determines required length of base64 characters for a given length of a byte string.
    protected
                    getLengthBase64FromBytes(int $byteLength) : int
    Parameters
- $byteLength : int
 - 
                    
Length of bytes to calculate in base64 chars
 
Return values
int —Required length of base64 characters
isValidSalt()
Method determines if a given string is a valid salt
    protected
                    isValidSalt(string $salt) : bool
    Parameters
- $salt : string
 - 
                    
String to check
 
Return values
bool —TRUE if it's valid salt, otherwise FALSE