-
-
Save mdzwigala/fa5f45e185613ba9438d25054204298a to your computer and use it in GitHub Desktop.
ADR-EXAMPLE\Infrastructure\Md5PasswordEncoder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(strict_types=1); | |
namespace App\Infrastructure\Service; | |
use App\Domain\Service\PasswordEncoder; | |
final class Md5PasswordEncoder implements PasswordEncoder | |
{ | |
private string $salt; | |
public function __construct(string $salt) | |
{ | |
$this->salt = $salt; | |
} | |
public function encode(string $password): string | |
{ | |
return md5($this->salt . $password); | |
} | |
public function matches(string $givenPassword, string $password): bool | |
{ | |
return $this->encode($givenPassword) === $password; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, I like the whole ADR example but could you, please, replace MD5 with proper password_hash/password_verify (with Argon algo of course)?
Some devs might think that hashing password to MD5 is good, but it is not at all.