maj: sémantique, révision vérification ppassword
This commit is contained in:
9
src/SQLLogin/Exception/InvalidSQLLoginException.php
Normal file
9
src/SQLLogin/Exception/InvalidSQLLoginException.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\SQLLogin\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidSQLLoginException extends Exception
|
||||
{
|
||||
}
|
9
src/SQLLogin/Exception/InvalidSQLPasswordException.php
Normal file
9
src/SQLLogin/Exception/InvalidSQLPasswordException.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\SQLLogin\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidSQLPasswordException extends Exception
|
||||
{
|
||||
}
|
48
src/SQLLogin/SQLLoginConnect.php
Normal file
48
src/SQLLogin/SQLLoginConnect.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\SQLLogin;
|
||||
|
||||
use PDO;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class SQLLoginConnect extends AbstractController
|
||||
{
|
||||
/**
|
||||
* @var Singleton
|
||||
* @static
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Constructeur de la classe
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Méthode qui crée l'unique instance de la classe
|
||||
* si elle n'existe pas encore puis la retourne.
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return PdoConnect
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (is_null(self::$_instance)) {
|
||||
self::$_instance = new SQLLoginConnect();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
public function connect($urlDatabase, $dbUser, $dbPassword)
|
||||
{
|
||||
return new PDO($urlDatabase, $dbUser, $dbPassword);
|
||||
}
|
||||
}
|
77
src/SQLLogin/SQLLoginRequest.php
Normal file
77
src/SQLLogin/SQLLoginRequest.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\SQLLogin;
|
||||
|
||||
class SQLLoginRequest
|
||||
{
|
||||
public const DATA_TO_FETCH = 'data_to_fetch';
|
||||
public const LOGIN_COLUMN_NAME = 'login_column_name';
|
||||
public const SALT_COLUMN_NAME = 'salt_column_name';
|
||||
public const PASSWORD_COLUMN_NAME = 'password_column_name';
|
||||
public const TABLE_NAME = 'table_name';
|
||||
|
||||
protected array $config;
|
||||
protected string $dsn;
|
||||
protected string $user;
|
||||
protected string $password;
|
||||
|
||||
public function __construct(array $config = [], string $dsn, string $user, string $password)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->dsn = $dsn;
|
||||
$this->user = $user;
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function getDatabaseDsn()
|
||||
{
|
||||
return $this->dsn;
|
||||
}
|
||||
|
||||
public function getDbUser()
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function getDbPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
public function getLoginColumnName()
|
||||
{
|
||||
return $this->config[self::LOGIN_COLUMN_NAME];
|
||||
}
|
||||
|
||||
public function egtPasswordColumnName()
|
||||
{
|
||||
return $this->config[self::PASSWORD_COLUMN_NAME];
|
||||
}
|
||||
|
||||
public function getSaltColumnName()
|
||||
{
|
||||
return $this->config[self::SALT_COLUMN_NAME];
|
||||
}
|
||||
|
||||
public function getRequestScope()
|
||||
{
|
||||
$scope = '';
|
||||
foreach ($this->config[self::DATA_TO_FETCH] as $data) {
|
||||
$scope .= $data.',';
|
||||
}
|
||||
$scope = substr($scope, 0, -1);
|
||||
$request = 'SELECT '.$scope.' FROM '.$this->config[self::TABLE_NAME].' WHERE '.$this->config[self::LOGIN_COLUMN_NAME].' = :'.$this->config[self::LOGIN_COLUMN_NAME].';';
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
public function getRequestPassword()
|
||||
{
|
||||
$passwordColumns = $this->config[self::PASSWORD_COLUMN_NAME];
|
||||
if (!empty($this->config[self::SALT_COLUMN_NAME])) {
|
||||
$passwordColumns .= ', '.$this->config[self::SALT_COLUMN_NAME];
|
||||
}
|
||||
|
||||
return 'SELECT '.$passwordColumns.' FROM '.$this->config[self::TABLE_NAME].' WHERE '.$this->config[self::LOGIN_COLUMN_NAME].' = :'.$this->config[self::LOGIN_COLUMN_NAME].';';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user