Skip to content

Commit 1ae989e

Browse files
committed
Support Laravel 11.x and PHP 8.3
1 parent af6180a commit 1ae989e

File tree

4 files changed

+55
-8
lines changed

4 files changed

+55
-8
lines changed

.github/workflows/php.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ jobs:
1010
strategy:
1111
matrix:
1212
include:
13+
- php: 8.3
14+
illuminate: ^11.0
1315
- php: 8.2
1416
illuminate: ^10.0
1517
- php: 8.1
@@ -39,4 +41,4 @@ jobs:
3941
run: composer run-script ci-test
4042

4143
- uses: codecov/codecov-action@v3
42-
if: matrix.php == '8.2'
44+
if: matrix.php == '8.3'

composer.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@
2020
"ci-test": "vendor/bin/phpunit --coverage-clover coverage.xml"
2121
},
2222
"require": {
23-
"php": "^7.3|^7.4|^8.0|^8.1|^8.2",
24-
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0",
25-
"illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0",
26-
"illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0",
27-
"illuminate/hashing": "^6.0|^7.0|^8.0|^9.0|^10.0",
23+
"php": "^7.3|^7.4|^8.0|^8.1|^8.2|^8.3",
24+
"illuminate/support": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
25+
"illuminate/container": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
26+
"illuminate/database": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
27+
"illuminate/hashing": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
2828
"aws/aws-sdk-php": "^3.0"
2929
},
3030
"require-dev": {
31-
"illuminate/auth": "^6.0|^7.0|^8.0|^9.0|^10.0",
32-
"symfony/var-dumper": "^5.0|^6.0",
31+
"illuminate/auth": "^6.0|^7.0|^8.0|^9.0|^10.0|^11.0",
32+
"symfony/var-dumper": "^5.0|^6.0|^7.0",
3333
"vlucas/phpdotenv": "^4.1|^5.0",
3434
"mockery/mockery": "^1.3",
3535
"phpunit/phpunit": "^8.0|^9.0|^10.0"

src/Kitar/Dynamodb/Model/AuthUserProvider.php

+23
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ public function validateCredentials(Authenticatable $user, array $credentials)
147147
return $this->hasher->check($plain, $user->getAuthPassword());
148148
}
149149

150+
/**
151+
* Rehash the user's password if required and supported.
152+
*
153+
* @param \Illuminate\Contracts\Auth\Authenticatable $user
154+
* @param array $credentials
155+
* @param bool $force
156+
* @return void
157+
*/
158+
public function rehashPasswordIfRequired(Authenticatable $user, array $credentials, bool $force = false)
159+
{
160+
if (! method_exists(BaseUserProvider::class, 'rehashPasswordIfRequired')) {
161+
return;
162+
}
163+
164+
if (! $this->hasher->needsRehash($user->getAuthPassword()) && ! $force) {
165+
return;
166+
}
167+
168+
$user->forceFill([
169+
$user->getAuthPasswordName() => $this->hasher->make($credentials['password']),
170+
])->save();
171+
}
172+
150173
/**
151174
* Create a new instance of the model.
152175
*

tests/Model/AuthUserProviderTest.php

+22
Original file line numberDiff line numberDiff line change
@@ -376,4 +376,26 @@ public function it_can_validate_credentials()
376376
$this->assertTrue($success);
377377
$this->assertFalse($fail);
378378
}
379+
380+
/** @test */
381+
public function it_can_rehash_password_if_required()
382+
{
383+
$connection = $this->newConnectionMock();
384+
$connection->shouldReceive('putItem')->andReturn($this->sampleAwsResult());
385+
$this->setConnectionResolver($connection);
386+
387+
$originalHash = '$2y$10$ouGGlM0C/YKgk8MbQHxVHOblxztk/PlXZbKw7w2wfA8FlXsB0Po9G';
388+
$user = new UserA([
389+
'partition' => '[email protected]',
390+
'password' => $originalHash,
391+
]);
392+
$provider = new AuthUserProvider($this->hasher, UserA::class);
393+
$provider->rehashPasswordIfRequired($user, ['password' => 'foo'], true);
394+
$this->assertNotSame($originalHash, $user->password);
395+
$this->assertTrue($this->hasher->check('foo', $user->password));
396+
397+
$rehashedHash = $user->password;
398+
$provider->rehashPasswordIfRequired($user, ['password' => 'foo']);
399+
$this->assertSame($rehashedHash, $user->password);
400+
}
379401
}

0 commit comments

Comments
 (0)