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

Commit cbfec9c

Browse files
committed
Merge branch 'feature/46'
Close #46
2 parents 96878e4 + 9c49a5e commit cbfec9c

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

docs/book/adapter/dbtable/callback-check.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ As an example, many websites require a user to activate their account before
214214
allowing them to login for the first time. We can add that criteria as follows:
215215

216216
```php
217-
// Create a basic adapter, with only an MD5() credential treatment:
217+
// Create a basic adapter
218218
$adapter = new AuthAdapter(
219219
$db,
220220
'users',

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

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@
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) or
11+
[`crypt()` for PostgreSQL](https://www.postgresql.org/docs/11/pgcrypto.html#id-1.11.7.34.6).
12+
More details are available in the next section.
13+
14+
## Security considerations
15+
16+
Passing passwords to database in plaintext for insert or verification is
17+
generally not recommended.
18+
Sql statements can and usually are logged by the database, and passwords in them
19+
become visible to anyone with access to the logs or monitoring tools that
20+
consume those logs.
21+
22+
The safer approach is to hash passwords, and to verify them against a stored
23+
hash in your application code. This way the password never leaves the
24+
application, and only the hashed value is exchanged with the database.
25+
26+
As such, this adapter is not recommended for new applications, and existing
27+
applications should consider migrating to using PHP-provided password handling
28+
functions such as `password_hash()` and `password_verify()`. See
29+
[CallbackCheckAdapter](callback-check.md) for more info.
830

931
## Configuration Options
1032

@@ -23,7 +45,7 @@ The available configuration options include:
2345
- `credentialTreatment`: In many cases, passwords and other sensitive data
2446
are encrypted, hashed, encoded, obscured, salted or otherwise treated through
2547
some function or algorithm. By specifying a parameterized treatment string
26-
with this method, such as '`MD5(?)`' or '`PASSWORD(?)`', a developer may
48+
with this method, such as '`PASSWORD(?)`', a developer may
2749
apply such arbitrary SQL upon input credential data. Since these functions
2850
are specific to the underlying RDBMS, check the database manual for the
2951
availability of such functions for your database system.
@@ -186,7 +208,7 @@ credential treatment to solve more complex problems.
186208

187209
### Check for compromised user
188210

189-
In this scenario, we use the credential treatment `MD5()`, but also check to see
211+
In this scenario, we use the credential treatment `PASSWORD()`, but also check to see
190212
that the user has not been flagged as "compromised", which is a potential value
191213
of the `status` field for the user record.
192214

@@ -199,7 +221,7 @@ $adapter = new AuthAdapter(
199221
'users',
200222
'username',
201223
'password',
202-
'MD5(?) AND status != "compromised"'
224+
'PASSWORD(?) AND status != "compromised"'
203225
);
204226
```
205227

@@ -218,7 +240,7 @@ $adapter = new AuthAdapter(
218240
'users',
219241
'username',
220242
'password',
221-
'MD5(?) AND active = "TRUE"'
243+
'PASSWORD(?) AND active = "TRUE"'
222244
);
223245
```
224246

@@ -238,7 +260,9 @@ $sqlAlter = "ALTER TABLE [users] "
238260
. "AFTER [password]";
239261
```
240262

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`:
263+
Salts should be created *for each user* using a cryptographically sound pseudo-random number generator (CSPRNG).
264+
PHP 7 provides an implementation via `random_bytes()` (and
265+
the [random_compat package provides them for older, supported versions of PHP](https://github.com/paragonie/random_compat)):
242266

243267
```php
244268
$salt = random_bytes(32);
@@ -267,7 +291,7 @@ $db,
267291
'users',
268292
'username',
269293
'password',
270-
"MD5(CONCAT('staticSalt', ?, password_salt))"
294+
"PASSWORD(CONCAT('staticSalt', ?, password_salt))"
271295
);
272296
```
273297

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

306330
```php
307-
// Create a basic adapter, with only an MD5() credential treatment:
331+
// Create a basic adapter, with only an PASSWORD() credential treatment:
308332
$adapter = new AuthAdapter(
309333
$db,
310334
'users',
311335
'username',
312336
'password',
313-
'MD5(?)'
337+
'PASSWORD(?)'
314338
);
315339

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

0 commit comments

Comments
 (0)