add PasswordHasher interface with bcrypt implementation
Introduce an injectable abstraction over password_hash and password_verify so callers can be swapped for a fast fake in tests without paying bcrypt's CPU cost. The bcrypt implementation is a direct passthrough using PASSWORD_DEFAULT, matching the prior inline behavior, so existing stored hashes continue to verify. Wired into the DI container alongside the other auth primitives (Clock, TokenGenerator). No callers reference it yet, so production behavior is unchanged.
This commit is contained in:
parent
d93b668d5a
commit
b1247d2fa1
3 changed files with 29 additions and 0 deletions
16
app/Auth/BcryptPasswordHasher.php
Normal file
16
app/Auth/BcryptPasswordHasher.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Auth;
|
||||
|
||||
class BcryptPasswordHasher implements PasswordHasher
|
||||
{
|
||||
public function hash(string $plaintext): string
|
||||
{
|
||||
return password_hash($plaintext, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
public function verify(string $plaintext, string $hash): bool
|
||||
{
|
||||
return password_verify($plaintext, $hash);
|
||||
}
|
||||
}
|
||||
10
app/Auth/PasswordHasher.php
Normal file
10
app/Auth/PasswordHasher.php
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?php
|
||||
|
||||
namespace App\Auth;
|
||||
|
||||
interface PasswordHasher
|
||||
{
|
||||
public function hash(string $plaintext): string;
|
||||
|
||||
public function verify(string $plaintext, string $hash): bool;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue