summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/general/compatibility_functions.rst
blob: 398403edafd905cf32a3ff29270569599f9eadd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#######################
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>`_.

*********************
Hash (Message Digest)
*********************

This compatibility layer contains only a single function at
this time - ``hash_pbkdf2()``, which otherwise requires PHP 5.5.

Dependancies
============

- None

Function reference
==================

.. function:: hash_pbkdf2($algo, $password, $salt, $iterations[, $length = 0[, $raw_output = FALSE]])

	:param	string	$algo: Hashing algorithm
	:param	string	$password: Password
	:param	string	$salt: Hash salt
	:param	int	$iterations: Number of iterations to perform during derivation
	:param	int	$length: Output string length
	:param	bool	$raw_output: Whether to return raw binary data
	:returns:	Password-derived key or FALSE on failure
	:rtype:	string

	For more information, please refer to the `PHP manual for
	hash_pbkdf2() <http://php.net/hash_pbkdf2>`_.

****************
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>`_.

***************
Array Functions
***************

This set of compatibility functions offers support for a few
standard `Array Functions <http://php.net/book.array>`_ in PHP
that otherwise require a newer PHP version.

Dependancies
============

- None

Function reference
==================

.. function:: array_column(array $array, $column_key[, $index_key = NULL])

	:param	array	$array: Array to fetch results from
	:param	mixed	$column_key: Key of the column to return values from
	:param	mixed	$index_key: Key to use for the returned values
	:returns:	An array of values representing a single column from the input array
	:rtype:	array

	For more information, please refer to the `PHP manual for
	array_column() <http://php.net/array_column>`_.

.. function:: array_replace(array $array1[, ...])

	:param	array	$array1: Array in which to replace elements
	:param	array	...: Array (or multiple ones) from which to extract elements
	:returns:	Modified array
	:rtype:	array

	For more information, please refer to the `PHP manual for
	array_replace() <http://php.net/array_replace>`_.

.. function:: array_replace_recursive(array $array1[, ...])

	:param	array	$array1: Array in which to replace elements
	:param	array	...: Array (or multiple ones) from which to extract elements
	:returns:	Modified array
	:rtype:	array

	For more information, please refer to the `PHP manual for
	array_replace_recursive() <http://php.net/array_replace_recursive>`_.

	.. important:: Only PHP's native function can detect endless recursion.
		Unless you are running PHP 5.3+, be careful with references!