3
3
` Zend\Authentication\Adapter\DbTable\CredentialTreatmentAdapter ` will execute a
4
4
SQL query containing the provided identity and credentials, passing the
5
5
credentials to a * credential treatment* function defined on the RDBMS server;
6
- if an identity is returned, authentication succeeds. Common credential
7
- treatments include ` MD5() ` and ` PASSWORD() ` .
6
+ if an identity is returned, authentication succeeds. Credential
7
+ treatments depends on your RDBMS, and while simple hashing function such as
8
+ ` md5 ` and ` sha1 ` are generally available, it is recommended not to use them and
9
+ rather use the RDBMS specific function such as
10
+ [ ` PASSWORD(?) ` for MySQL] ( http://dev.mysql.com/doc/refman/5.7/en/password-hashing.html ) .
11
+ More details are available in the next section.
8
12
9
13
## Configuration Options
10
14
@@ -23,7 +27,7 @@ The available configuration options include:
23
27
- ` credentialTreatment ` : In many cases, passwords and other sensitive data
24
28
are encrypted, hashed, encoded, obscured, salted or otherwise treated through
25
29
some function or algorithm. By specifying a parameterized treatment string
26
- with this method, such as '` MD5(?) ` ' or ' ` PASSWORD(?) ` ', a developer may
30
+ with this method, such as '` PASSWORD(?) ` ', a developer may
27
31
apply such arbitrary SQL upon input credential data. Since these functions
28
32
are specific to the underlying RDBMS, check the database manual for the
29
33
availability of such functions for your database system.
@@ -186,7 +190,7 @@ credential treatment to solve more complex problems.
186
190
187
191
### Check for compromised user
188
192
189
- In this scenario, we use the credential treatment ` MD5 ()` , but also check to see
193
+ In this scenario, we use the credential treatment ` PASSWORD ()` , but also check to see
190
194
that the user has not been flagged as "compromised", which is a potential value
191
195
of the ` status ` field for the user record.
192
196
@@ -199,7 +203,7 @@ $adapter = new AuthAdapter(
199
203
'users',
200
204
'username',
201
205
'password',
202
- 'MD5 (?) AND status != "compromised"'
206
+ 'PASSWORD (?) AND status != "compromised"'
203
207
);
204
208
```
205
209
@@ -218,7 +222,7 @@ $adapter = new AuthAdapter(
218
222
'users',
219
223
'username',
220
224
'password',
221
- 'MD5 (?) AND active = "TRUE"'
225
+ 'PASSWORD (?) AND active = "TRUE"'
222
226
);
223
227
```
224
228
@@ -238,7 +242,9 @@ $sqlAlter = "ALTER TABLE [users] "
238
242
. "AFTER [password]";
239
243
```
240
244
241
- Salts should be created * for each user* using a cryptographically sound pseudo-random number generator (CSPRNG). PHP 7 provides an implementation via ` random_bytes ` :
245
+ Salts should be created * for each user* using a cryptographically sound pseudo-random number generator (CSPRNG).
246
+ PHP 7 provides an implementation via ` random_bytes ` (and
247
+ [ ` random_compat ` for older supported versions of PHP] ( https://github.com/paragonie/random_compat ) ):
242
248
243
249
``` php
244
250
$salt = random_bytes(32);
267
273
'users',
268
274
'username',
269
275
'password',
270
- "MD5 (CONCAT('staticSalt', ?, password_salt))"
276
+ "PASSWORD (CONCAT('staticSalt', ?, password_salt))"
271
277
);
272
278
```
273
279
@@ -304,13 +310,13 @@ The following uses the second example in this section, adding another `WHERE`
304
310
clause to determine if the user is active in the system.
305
311
306
312
``` php
307
- // Create a basic adapter, with only an MD5 () credential treatment:
313
+ // Create a basic adapter, with only an PASSWORD () credential treatment:
308
314
$adapter = new AuthAdapter(
309
315
$db,
310
316
'users',
311
317
'username',
312
318
'password',
313
- 'MD5 (?)'
319
+ 'PASSWORD (?)'
314
320
);
315
321
316
322
// Now retrieve the Select instance and modify it:
0 commit comments