Skip to content

Commit 6158336

Browse files
committed
Fixed SensitiveParameter attribute on passwords
1 parent 486b056 commit 6158336

File tree

5 files changed

+26
-11
lines changed

5 files changed

+26
-11
lines changed

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/tests export-ignore
2+
CHANGELOG.md export-ignore
3+
phpunit.xml export-ignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
vendor/
22
composer.lock
33
index.php
4+
test.php
45
.phpunit.result.cache
56
.phpunit.cache

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Released Notes
22

3+
## v3.1.2 - (2024-03-11)
4+
5+
### Fixed
6+
7+
- Fixed `SensitiveParameter` attribute on passwords
8+
9+
-----------------------------------------------------------
10+
311
## v3.1.1 - (2024-02-18)
412

513
### Fixed

src/PepperTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getPepper(): string
4747
$encryption = new Encryption(new OpenSslEncryption($this->pepper));
4848
$this->pepper = $encryption->decrypt($this->pepper);
4949
}
50-
50+
5151
if ($this->crypt_type == 'sodium') {
5252
$encryption = new Encryption(new SodiumEncryption($this->pepper));
5353
$this->pepper = $encryption->decrypt($this->pepper);
@@ -82,7 +82,7 @@ private function useSodium(): mixed
8282
*
8383
* @return string
8484
*/
85-
private function passwordPeppered(string $password): string
85+
private function passwordPeppered(#[\SensitiveParameter] string $password): string
8686
{
8787
return hash_hmac("sha256", $password, $this->getPepper());
8888
}

src/SecurePassword.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function __construct(
5050
*
5151
* @return SecurePassword
5252
*/
53-
public function createHash(string $password): SecurePassword
53+
public function createHash(#[\SensitiveParameter] string $password): SecurePassword
5454
{
5555
$this->password = $password;
5656
$pwd_peppered = $this->passwordPeppered($this->password);
@@ -90,8 +90,11 @@ public function getHashInfo(): mixed
9090
*
9191
* @return bool
9292
*/
93-
public function verifyHash(?string $password = null, ?string $hash = null, int $wait_microseconds = 250000): bool
94-
{
93+
public function verifyHash(
94+
#[\SensitiveParameter] ?string $password = null,
95+
#[\SensitiveParameter] ?string $hash = null,
96+
int $wait_microseconds = 250000
97+
): bool {
9598
if (is_null($password)) {
9699
$password = $this->password;
97100
}
@@ -121,10 +124,8 @@ public function verifyHash(?string $password = null, ?string $hash = null, int $
121124
*
122125
* @return int
123126
*/
124-
public static function getOptimalBcryptCost(
125-
string $password,
126-
int $min_ms = 250
127-
): int {
127+
public static function getOptimalBcryptCost(#[\SensitiveParameter] string $password, int $min_ms = 250): int
128+
{
128129
for ($i = 4; $i < 31; $i++) {
129130
$time_start = microtime(true);
130131
password_hash($password, PASSWORD_BCRYPT, ['cost' => $i]);
@@ -145,8 +146,10 @@ public static function getOptimalBcryptCost(
145146
*
146147
* @return string|false
147148
*/
148-
public function needsRehash(string $password, string $hash): string|false
149-
{
149+
public function needsRehash(
150+
#[\SensitiveParameter] string $password,
151+
#[\SensitiveParameter] string $hash
152+
): string|false {
150153
if (password_needs_rehash($hash, $this->algo)) {
151154
return $this->createHash($password)->getHash();
152155
}

0 commit comments

Comments
 (0)