Server : Apache System : Linux webd348.cluster026.gra.hosting.ovh.net 5.15.148-ovh-vps-grsec-zfs-classid #1 SMP Thu Feb 8 09:41:04 UTC 2024 x86_64 User : hednacluml ( 122243) PHP Version : 8.3.9 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl Directory : /home/hednacluml/france/ecrire/src/Chiffrer/ |
<?php /***************************************************************************\ * SPIP, Système de publication pour l'internet * * * * Copyright © avec tendresse depuis 2001 * * Arnaud Martin, Antoine Pitrou, Philippe Rivière, Emmanuel Saint-James * * * * Ce programme est un logiciel libre distribué sous licence GNU/GPL. * \***************************************************************************/ namespace Spip\Chiffrer; /** Vérification et hachage de mot de passe */ class Password { /** * verifier qu'un mot de passe en clair est correct a l'aide de son hash * * Le mot de passe est poivre via la cle secret_des_auth * * @param string $password_clair * @param string $password_hash * @param string $key * @return bool */ public static function verifier( #[\SensitiveParameter] string $password_clair, #[\SensitiveParameter] string $password_hash, #[\SensitiveParameter] ?string $key = null ): bool { $key ??= self::getDefaultKey(); if ($key) { $pass_poivre = hash_hmac('sha256', $password_clair, $key); return password_verify($pass_poivre, $password_hash); } spip_log('Aucune clé pour vérifier le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE); return false; } /** * Calculer un hash salé du mot de passe * @param string $password_clair * @param string $salt * @return string */ public static function hacher( #[\SensitiveParameter] string $password_clair, #[\SensitiveParameter] ?string $key = null ): ?string { $key ??= self::getDefaultKey(); // ne pas fournir un hash errone si la cle nous manque if ($key) { $pass_poivre = hash_hmac('sha256', $password_clair, $key); return password_hash($pass_poivre, PASSWORD_DEFAULT); } spip_log('Aucune clé pour chiffrer le mot de passe', 'chiffrer' . _LOG_INFO_IMPORTANTE); return null; } private static function getDefaultKey(): ?string { $keys = SpipCles::instance(); return $keys->getSecretAuth(); } }