Andrey Andreev | 81f0367 | 2014-02-13 17:57:41 +0200 | [diff] [blame] | 1 | ####################### |
| 2 | Compatibility Functions |
| 3 | ####################### |
| 4 | |
| 5 | CodeIgniter provides a set of compatibility functions that enable |
| 6 | you to use functions what are otherwise natively available in PHP, |
| 7 | but only in higher versions or depending on a certain extension. |
| 8 | |
| 9 | Being custom implementations, these functions will also have some |
| 10 | set of dependancies on their own, but are still useful if your |
| 11 | PHP setup doesn't offer them natively. |
| 12 | |
| 13 | .. note:: Much like the `common functions <common_functions>`, the |
| 14 | compatibility functions are always available, as long as |
| 15 | their dependancies are met. |
| 16 | |
| 17 | .. contents:: |
| 18 | :local: |
| 19 | |
| 20 | .. raw:: html |
| 21 | |
| 22 | <div class="custom-index container"></div> |
| 23 | |
| 24 | **************** |
| 25 | Password Hashing |
| 26 | **************** |
| 27 | |
| 28 | This set of compatibility functions offers a "backport" of PHP's |
| 29 | standard `Password Hashing extension <http://php.net/password>`_ |
| 30 | that is otherwise available only since PHP 5.5. |
| 31 | |
| 32 | Dependancies |
| 33 | ============ |
| 34 | |
| 35 | - PHP 5.3.7 |
| 36 | - ``CRYPT_BLOWFISH`` support for ``crypt()`` |
| 37 | |
| 38 | Constants |
| 39 | ========= |
| 40 | |
| 41 | - ``PASSWORD_BCRYPT`` |
| 42 | - ``PASSWORD_DEFAULT`` |
| 43 | |
| 44 | Function reference |
| 45 | ================== |
| 46 | |
| 47 | .. function:: password_get_info($hash) |
| 48 | |
| 49 | :param string $hash: Password hash |
| 50 | :returns: Information about the hashed password |
| 51 | :rtype: array |
| 52 | |
| 53 | For more information, please refer to the `PHP manual for |
| 54 | password_get_info() <http://php.net/password_get_info>`_. |
| 55 | |
| 56 | .. function:: password_hash($password, $algo[, $options = array()]) |
| 57 | |
| 58 | :param string $password: Plain-text password |
| 59 | :param int $algo: Hashing algorithm |
| 60 | :param array $options: Hashing options |
| 61 | :returns: Hashed password or FALSE on failure |
| 62 | :rtype: string |
| 63 | |
| 64 | For more information, please refer to the `PHP manual for |
| 65 | password_hash() <http://php.net/password_hash>`_. |
| 66 | |
| 67 | .. note:: Unless you provide your own (and valid) salt, this function |
| 68 | has a further dependancy on an available CSPRNG source. Each |
| 69 | of the following would satisfy that: |
| 70 | - ``mcrypt_create_iv()`` with ``MCRYPT_DEV_URANDOM`` |
| 71 | - ``openssl_random_pseudo_bytes()`` |
| 72 | - /dev/arandom |
| 73 | - /dev/urandom |
| 74 | |
| 75 | .. function:: password_needs_rehash() |
| 76 | |
| 77 | :param string $hash: Password hash |
| 78 | :param int $algo: Hashing algorithm |
| 79 | :param array $options: Hashing options |
| 80 | :returns: TRUE if the hash should be rehashed to match the given algorithm and options, FALSE otherwise |
| 81 | :rtype: bool |
| 82 | |
| 83 | For more information, please refer to the `PHP manual for |
| 84 | password_needs_rehash() <http://php.net/password_needs_rehash>`_. |
| 85 | |
| 86 | .. function:: password_verify($password, $hash) |
| 87 | |
| 88 | :param string $password: Plain-text password |
| 89 | :param string $hash: Password hash |
| 90 | :returns: TRUE if the password matches the hash, FALSE if not |
| 91 | :rtype: bool |
| 92 | |
| 93 | For more information, please refer to the `PHP manual for |
| 94 | password_verify() <http://php.net/password_verify>`_. |
| 95 | |
| 96 | **************** |
| 97 | Multibyte String |
| 98 | **************** |
| 99 | |
| 100 | This set of compatibility functions offers limited support for PHP's |
| 101 | `Multibyte String extension <http://php.net/mbstring>`_. Because of |
| 102 | the limited alternative solutions, only a few functions are available. |
| 103 | |
| 104 | .. note:: When a character set parameter is ommited, |
| 105 | ``$config['charset']`` will be used. |
| 106 | |
| 107 | Dependancies |
| 108 | ============ |
| 109 | |
| 110 | - `iconv <http://php.net/iconv>`_ extension |
| 111 | |
| 112 | .. important:: This dependancy is optional and these functions will |
| 113 | always be declared. If iconv is not available, they WILL |
| 114 | fall-back to their non-mbstring versions. |
| 115 | |
| 116 | .. important:: Where a character set is supplied, it must be |
| 117 | supported by iconv and in a format that it recognizes. |
| 118 | |
| 119 | .. note:: For you own dependancy check on the actual mbstring |
| 120 | extension, use the ``MB_ENABLED`` constant. |
| 121 | |
| 122 | Function reference |
| 123 | ================== |
| 124 | |
| 125 | .. function:: mb_strlen($str[, $encoding = NULL]) |
| 126 | |
| 127 | :param string $str: Input string |
| 128 | :param string $encoding: Character set |
| 129 | :returns: Number of characters in the input string or FALSE on failure |
| 130 | :rtype: string |
| 131 | |
| 132 | For more information, please refer to the `PHP manual for |
| 133 | mb_strlen() <http://php.net/mb_strlen>`_. |
| 134 | |
| 135 | .. function:: mb_strpos($haystack, $needle[, $offset = 0[, $encoding = NULL]]) |
| 136 | |
| 137 | :param string $haystack: String to search in |
| 138 | :param string $needle: Part of string to search for |
| 139 | :param int $offset: Search offset |
| 140 | :param string $encoding: Character set |
| 141 | :returns: Numeric character position of where $needle was found or FALSE if not found |
| 142 | :rtype: mixed |
| 143 | |
| 144 | For more information, please refer to the `PHP manual for |
| 145 | mb_strpos() <http://php.net/mb_strpos>`_. |
| 146 | |
| 147 | .. function:: mb_substr($str, $start[, $length = NULL[, $encoding = NULL]]) |
| 148 | |
| 149 | :param string $str: Input string |
| 150 | :param int $start: Position of first character |
| 151 | :param int $length: Maximum number of characters |
| 152 | :param string $encoding: Character set |
| 153 | :returns: Portion of $str specified by $start and $length or FALSE on failure |
| 154 | :rtype: string |
| 155 | |
| 156 | For more information, please refer to the `PHP manual for |
| 157 | mb_substr() <http://php.net/mb_substr>`_. |