From f19d68ae93d52ed84377d18a4a6b58e3c20cb9c3 Mon Sep 17 00:00:00 2001 From: rudy Date: Fri, 6 Jan 2023 17:06:29 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20d'une=20methode=20sp=C3=A9cifique=20?= =?UTF-8?q?=C3=A0=20ssha?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/services.yaml | 2 +- src/Security/Hasher/PasswordEncoder.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config/services.yaml b/config/services.yaml index 2b7950e..19a755d 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -27,7 +27,7 @@ parameters: locales: '%env(APP_LOCALES)%' app.supported_locales: ~ - env(PEPPER): "257d62c24cd352c21b51c26dba678c8ff05011a89022aec106185bf67c69aa8b" + env(PEPPER): "" pepper: '%env(resolve:PEPPER)%' services: # default configuration for services in *this* file diff --git a/src/Security/Hasher/PasswordEncoder.php b/src/Security/Hasher/PasswordEncoder.php index be4fbc9..2317acf 100644 --- a/src/Security/Hasher/PasswordEncoder.php +++ b/src/Security/Hasher/PasswordEncoder.php @@ -47,6 +47,9 @@ class PasswordEncoder implements LegacyPasswordHasherInterface $completedPassword = $this->getPasswordToHash($plainPassword, $salt); foreach ($this->hashAlgoLegacy as $algo) { + if ('ssha' === $algo) { + return $this->compareSsha($hashedPassword, $completedPassword); + } if ($this->isObsoleteAlgo($algo)) { if (hash_equals(hash($algo, $completedPassword), $hashedPassword)) { return true; @@ -98,4 +101,17 @@ class PasswordEncoder implements LegacyPasswordHasherInterface return $completedPlainPassword; } + + protected function compareSsha($hashPassword, $plainPassword) + { + $base_64_hash_with_salt = substr($hashPassword, 6); + $hash_with_salt = base64_decode($base_64_hash_with_salt); + $hash = substr($hash_with_salt, 0, 20); + $salt = substr($hash_with_salt, 20); + + // hash given password + $hash_given = sha1($plainPassword.$salt, true); + + return $hash == $hash_given; + } }