A1_Core::hash PHP Method

hash() public method

Generates bcrypt hash for input
public hash ( $input, $salt = NULL, $cost = NULL ) : string
return string hashed input value
    public function hash($input, $salt = NULL, $cost = NULL)
    {
        if (!$salt) {
            // Generate a random 22 character salt
            $salt = Text::random(self::SALT, 22);
        }
        if (!$cost) {
            $cost = $this->_config['cost'];
        }
        // Apply 0 padding to the cost, normalize to a range of 4-31
        $cost = sprintf('%02d', min(31, max($cost, 4)));
        // Create a salt suitable for bcrypt
        $salt = '$2a$' . $cost . '$' . $salt . '$';
        return crypt($input, $salt);
    }