login consent app sql
This commit is contained in:
57
src/Services/PdoServices.php
Normal file
57
src/Services/PdoServices.php
Normal file
@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
|
||||
class PdoServices extends AbstractController
|
||||
{
|
||||
private $params;
|
||||
|
||||
public function __construct(ParameterBagInterface $params)
|
||||
{
|
||||
$this->params = $params;
|
||||
}
|
||||
|
||||
public function connection()
|
||||
{
|
||||
return new PDO($this->params->get('urlDatabase'), $this->params->get('dbUser'), $this->params->get('dbPassword'));
|
||||
}
|
||||
|
||||
public function fetchDatas($email)
|
||||
{
|
||||
try {
|
||||
$dbh = $this->connection();
|
||||
$datas = $dbh->query("SELECT " . $this->getParameter('fetchDatas'). " from USER where email = '" . $email . "';")->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
} catch (PDOException $e) {
|
||||
print "Erreur !: " . $e->getMessage() . "<br/>";
|
||||
die();
|
||||
}
|
||||
return $datas;
|
||||
}
|
||||
|
||||
public function verifyPassword($password, $hashedPassword)
|
||||
{
|
||||
$hashMethod = $this->params->get('hashMethod');
|
||||
switch ($hashMethod){
|
||||
case "sha1":
|
||||
return $hashedPassword === sha1($password, false);
|
||||
break;
|
||||
case "md5":
|
||||
return $hashedPassword === md5($password);
|
||||
break;
|
||||
case "BCRYPT":
|
||||
default:
|
||||
return password_verify($password, $hashedPassword);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user