params = $params;
$this->pdoRequest = $pdoRequest;
}
public function fetchDatas($login)
{
try {
$dbh = $this->getConnection();
// forge de la requête
$request = $this->pdoRequest->getRequestScope();
// Préparation de la requête
$query = $dbh->prepare($request);
$query->execute([$this->pdoRequest->getNameLogin() => $login]);
$datas = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo 'Erreur fetch Datas !: '.$e->getMessage().'
';
exit();
}
return $datas;
}
/**
* @param mixed $login
*
* @return bool
*/
public function fetchPassword($login)
{
try {
$dbh = $this->getConnection();
$request = $this->pdoRequest->getRequestLogin();
$query = $dbh->prepare($request);
$query->execute([$this->pdoRequest->getNameLogin() => $login]);
$password = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo 'Erreur fetch Password!: '.$e->getMessage().'
';
exit();
}
return $password[$this->pdoRequest->getNamePassword()];
}
public function getConnection()
{
// Appel du singleton
$pdo = PdoConnect::getInstance();
// Connection bdd
return $pdo->connect($this->pdoRequest->getDatabaseDsn(), $this->pdoRequest->getDbUser(), $this->pdoRequest->getDbPassword());
}
public function verifyPassword($password, $hashedPassword)
{
$hashAlgo = $this->params->get('hashAlgo') ?? 'sha256';
if ($hashedPassword === hash($hashAlgo, $password)) {
return true;
} else {
throw new InvalidPasswordException();
}
}
}