|
| 1 | +# Changelog |
| 2 | + |
| 3 | +## 2.0.0 |
| 4 | + |
| 5 | +### New Password Hasher |
| 6 | + |
| 7 | +Version `2.0.0` comes with a new password hasher component: `AngryBytes\Hash\Hasher\Password`. |
| 8 | +This hasher is intended to be used for hashing of passwords (and other secure tokens). |
| 9 | + |
| 10 | +The hasher utilises PHP's native cryptographically strong password hashing functions: |
| 11 | +`password_hash()` and `password_verify()`, see [Password Hashing](http://php.net/manual/en/book.password.php). |
| 12 | + |
| 13 | +The password hasher has been setup to use PHP's default cost and algorithm. |
| 14 | +The default cost can however be overwritten by providing a cost to the the constructor, like so: |
| 15 | + |
| 16 | +```php |
| 17 | +// Create a password hasher with n cost factor of 15 instead of the default (10). |
| 18 | +$passwordHasher = new \AngryBytes\Hash\Hasher\Password(15); |
| 19 | +``` |
| 20 | + |
| 21 | +#### Password Rehashing |
| 22 | +The password hasher offers a method to check if an existing hash needs to be **rehashed**. |
| 23 | +For example, this can be the case when the cost and/or algorithm of the password |
| 24 | +hasher has changed. If this is the case, you **should** rehash the password |
| 25 | +and update the stored hash with the rehashed value. |
| 26 | + |
| 27 | +**Example** |
| 28 | + |
| 29 | +In this example, we check whether an existing password is outdated and should be rehashed. |
| 30 | + |
| 31 | +Note: in order to rehash the password, you will need access to its original plaintext value. |
| 32 | +Therefore, it's probably a best practice to check for and update a stale hash |
| 33 | +during login procedure, where the plaintext password is available after a login form |
| 34 | +submit. |
| 35 | + |
| 36 | +```php |
| 37 | +// Create a password hasher |
| 38 | +$hasher = new \AngryBytes\Hash\Hash( |
| 39 | + new \AngryBytes\Hash\Hasher\Password |
| 40 | +); |
| 41 | + |
| 42 | +// Plaintext password received via form submit. |
| 43 | +$password = '...'; |
| 44 | + |
| 45 | +// Persisted password hash for the User |
| 46 | +$userPasswordHash = '...'; |
| 47 | + |
| 48 | +// Verify the password against the hash |
| 49 | +if ($hasher->verify($password, $userPasswordHash)) { |
| 50 | + |
| 51 | + // Check if the hash needs to be rehashed? |
| 52 | + if ($hasher->needsRehash($userPasswordHash)) { |
| 53 | + // Rehash password and update the user. |
| 54 | + $user->hash = $hasher->hash($password); |
| 55 | + $user->save(); |
| 56 | + } |
| 57 | +} |
| 58 | +``` |
| 59 | + |
| 60 | +### Refactored "AngryBytes\Hash\HasherInterface" |
| 61 | + |
| 62 | +Added new verification method `AngryBytes\Hash\HasherInterface::verify()` hash |
| 63 | +verification. This method accepts the following three arguments: |
| 64 | + |
| 65 | +* `$data` - The data that needs to be hashed. |
| 66 | +* `$hash` - The hash that needs to match the hashed value of `$data`. |
| 67 | +* `$options` (optional) - An array with addition hasher options. What these options are depends on the active hasher. |
| 68 | + |
| 69 | +### Refactored AngryBytes\Hash\Hash |
| 70 | + |
| 71 | +`AngryBytes\Hash\Hash::construct()` second argument (`$salt`) has become optional |
| 72 | +to accommodate for hashers that handle their own salt, like `AngryBytes\Hash\Hasher\Password`. |
| 73 | + |
| 74 | +`AngryBytes\Hash\Hash::hash()` and `AngryBytes\Hash\Hash::shortHash()` no longer accept any number of arguments but |
| 75 | +only following two: |
| 76 | + |
| 77 | +* `$data` - The data that needs to be hashed. This data can be of any type, all non-scalar types will be |
| 78 | + serialized before hashing. |
| 79 | +* `$options` (optional) - An array with options that will be passed to the hasher. What these options are depends |
| 80 | + on the active hasher. |
| 81 | + |
| 82 | +`AngryBytes\Hash\Hash::verify()` is a new method that's available to validate a hash in a time-safe manner. |
| 83 | +The method accepts the following arguments: |
| 84 | + |
| 85 | +* `$data` - The data that needs to be hashed. This data can be of any type, all non-scalar types will be |
| 86 | + serialized before hashing. |
| 87 | +* `$hash` - The hash that needs to match the hashed value of `$data`. |
| 88 | +* `$options` (optional) - An array with options that will be passed to the hasher. What these options are depends |
| 89 | + on the active hasher. |
| 90 | + |
| 91 | +`AngryBytes\Hash\Hash::matchesShortHash()` is replaced by `AngryBytes\Hash\Hash::verifyShortHash()` this methods |
| 92 | +accepts three arguments (`$data`, `$hash` and `$options`) just like `AngryBytes\Hash\Hash::verify()`. |
| 93 | + |
| 94 | +### Minor Changes |
| 95 | + |
| 96 | +* Scalar values passed to `hash()` and `shortHash()` are no longer serialized. |
| 97 | +* `AngryBytes\Hash::compare()` now uses PHP native (timing attack safe) `hash_equals()` function. |
| 98 | +* Fixed namespace issues for `AngryBytes\Hash\HMAC`. |
| 99 | +* `AngryBytes\Hash\Hash` now implements a `__call()` method that dynamically passes |
| 100 | + methods to the active hasher. This allows you to perform calls such as `AngryBytes\Hash::hash($string, ['cost' => 15]);` |
| 101 | + without having to call `AngryBytes\Hash::getHasher()` first. |
| 102 | + |
| 103 | +### Upgrading |
| 104 | + |
| 105 | +Please refer to the [upgrade notes](UPGRADING.md). |
| 106 | + |
| 107 | +### Deprecated & Removed Components |
| 108 | + |
| 109 | +* `AngryBytes\Hash\RandomString` has been removed. Better open-source random string generation |
| 110 | + libraries are available to do this. |
| 111 | + |
| 112 | +## 1.0.2 |
| 113 | +Valid Blowfish salts (22 char long composed of ./A-Za-z0-9 characters only) are now used as the salt as-is instead |
| 114 | +of md5-ed and substring-ed. |
| 115 | + |
| 116 | +## 1.0.1 |
| 117 | +Adding travis build status and scrutinizer code qual. img. to readme |
| 118 | + |
| 119 | +## 1.0.0 |
| 120 | +Initial release |
0 commit comments