Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit ef8e1c1

Browse files
committed
Cherry-pick "Remove insecure MD5 from documentation"
2 parents 6f54071 + db92a61 commit ef8e1c1

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

docs/book/adapter/dbtable/credential-treatment.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
`Zend\Authentication\Adapter\DbTable\CredentialTreatmentAdapter` will execute a
44
SQL query containing the provided identity and credentials, passing the
55
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.
812

913
## Configuration Options
1014

@@ -23,7 +27,7 @@ The available configuration options include:
2327
- `credentialTreatment`: In many cases, passwords and other sensitive data
2428
are encrypted, hashed, encoded, obscured, salted or otherwise treated through
2529
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
2731
apply such arbitrary SQL upon input credential data. Since these functions
2832
are specific to the underlying RDBMS, check the database manual for the
2933
availability of such functions for your database system.
@@ -186,7 +190,7 @@ credential treatment to solve more complex problems.
186190

187191
### Check for compromised user
188192

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
190194
that the user has not been flagged as "compromised", which is a potential value
191195
of the `status` field for the user record.
192196

@@ -199,7 +203,7 @@ $adapter = new AuthAdapter(
199203
'users',
200204
'username',
201205
'password',
202-
'MD5(?) AND status != "compromised"'
206+
'PASSWORD(?) AND status != "compromised"'
203207
);
204208
```
205209

@@ -218,7 +222,7 @@ $adapter = new AuthAdapter(
218222
'users',
219223
'username',
220224
'password',
221-
'MD5(?) AND active = "TRUE"'
225+
'PASSWORD(?) AND active = "TRUE"'
222226
);
223227
```
224228

@@ -238,7 +242,9 @@ $sqlAlter = "ALTER TABLE [users] "
238242
. "AFTER [password]";
239243
```
240244

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)):
242248

243249
```php
244250
$salt = random_bytes(32);
@@ -267,7 +273,7 @@ $db,
267273
'users',
268274
'username',
269275
'password',
270-
"MD5(CONCAT('staticSalt', ?, password_salt))"
276+
"PASSWORD(CONCAT('staticSalt', ?, password_salt))"
271277
);
272278
```
273279

@@ -304,13 +310,13 @@ The following uses the second example in this section, adding another `WHERE`
304310
clause to determine if the user is active in the system.
305311

306312
```php
307-
// Create a basic adapter, with only an MD5() credential treatment:
313+
// Create a basic adapter, with only an PASSWORD() credential treatment:
308314
$adapter = new AuthAdapter(
309315
$db,
310316
'users',
311317
'username',
312318
'password',
313-
'MD5(?)'
319+
'PASSWORD(?)'
314320
);
315321

316322
// Now retrieve the Select instance and modify it:

0 commit comments

Comments
 (0)