Skip to content

Instantly share code, notes, and snippets.

@mdzwigala
Created December 4, 2020 12:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdzwigala/fa5f45e185613ba9438d25054204298a to your computer and use it in GitHub Desktop.
Save mdzwigala/fa5f45e185613ba9438d25054204298a to your computer and use it in GitHub Desktop.
ADR-EXAMPLE\Infrastructure\Md5PasswordEncoder
<?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;
}
}
@PabloKowalczyk
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment