blob: e025d2aa3e09773e0c65b971bdcda3c8c81a9d9d [file] [log] [blame]
#######################
Compatibility Functions
#######################
CodeIgniter provides a set of compatibility functions that enable
you to use functions what are otherwise natively available in PHP,
but only in higher versions or depending on a certain extension.
Being custom implementations, these functions will also have some
set of dependancies on their own, but are still useful if your
PHP setup doesn't offer them natively.
.. note:: Much like the `common functions <common_functions>`, the
compatibility functions are always available, as long as
their dependancies are met.
.. contents::
:local:
.. raw:: html
<div class="custom-index container"></div>
****************
Password Hashing
****************
This set of compatibility functions offers a "backport" of PHP's
standard `Password Hashing extension <http://php.net/password>`_
that is otherwise available only since PHP 5.5.
Dependancies
============
- PHP 5.3.7
- ``CRYPT_BLOWFISH`` support for ``crypt()``
Constants
=========
- ``PASSWORD_BCRYPT``
- ``PASSWORD_DEFAULT``
Function reference
==================
.. function:: password_get_info($hash)
:param string $hash: Password hash
:returns: Information about the hashed password
:rtype: array
For more information, please refer to the `PHP manual for
password_get_info() <http://php.net/password_get_info>`_.
.. function:: password_hash($password, $algo[, $options = array()])
:param string $password: Plain-text password
:param int $algo: Hashing algorithm
:param array $options: Hashing options
:returns: Hashed password or FALSE on failure
:rtype: string
For more information, please refer to the `PHP manual for
password_hash() <http://php.net/password_hash>`_.
.. note:: Unless you provide your own (and valid) salt, this function
has a further dependancy on an available CSPRNG source. Each
of the following would satisfy that:
- ``mcrypt_create_iv()`` with ``MCRYPT_DEV_URANDOM``
- ``openssl_random_pseudo_bytes()``
- /dev/arandom
- /dev/urandom
.. function:: password_needs_rehash()
:param string $hash: Password hash
:param int $algo: Hashing algorithm
:param array $options: Hashing options
:returns: TRUE if the hash should be rehashed to match the given algorithm and options, FALSE otherwise
:rtype: bool
For more information, please refer to the `PHP manual for
password_needs_rehash() <http://php.net/password_needs_rehash>`_.
.. function:: password_verify($password, $hash)
:param string $password: Plain-text password
:param string $hash: Password hash
:returns: TRUE if the password matches the hash, FALSE if not
:rtype: bool
For more information, please refer to the `PHP manual for
password_verify() <http://php.net/password_verify>`_.
****************
Multibyte String
****************
This set of compatibility functions offers limited support for PHP's
`Multibyte String extension <http://php.net/mbstring>`_. Because of
the limited alternative solutions, only a few functions are available.
.. note:: When a character set parameter is ommited,
``$config['charset']`` will be used.
Dependancies
============
- `iconv <http://php.net/iconv>`_ extension
.. important:: This dependancy is optional and these functions will
always be declared. If iconv is not available, they WILL
fall-back to their non-mbstring versions.
.. important:: Where a character set is supplied, it must be
supported by iconv and in a format that it recognizes.
.. note:: For you own dependancy check on the actual mbstring
extension, use the ``MB_ENABLED`` constant.
Function reference
==================
.. function:: mb_strlen($str[, $encoding = NULL])
:param string $str: Input string
:param string $encoding: Character set
:returns: Number of characters in the input string or FALSE on failure
:rtype: string
For more information, please refer to the `PHP manual for
mb_strlen() <http://php.net/mb_strlen>`_.
.. function:: mb_strpos($haystack, $needle[, $offset = 0[, $encoding = NULL]])
:param string $haystack: String to search in
:param string $needle: Part of string to search for
:param int $offset: Search offset
:param string $encoding: Character set
:returns: Numeric character position of where $needle was found or FALSE if not found
:rtype: mixed
For more information, please refer to the `PHP manual for
mb_strpos() <http://php.net/mb_strpos>`_.
.. function:: mb_substr($str, $start[, $length = NULL[, $encoding = NULL]])
:param string $str: Input string
:param int $start: Position of first character
:param int $length: Maximum number of characters
:param string $encoding: Character set
:returns: Portion of $str specified by $start and $length or FALSE on failure
:rtype: string
For more information, please refer to the `PHP manual for
mb_substr() <http://php.net/mb_substr>`_.