v0.9.8 - minor bugfix in the auth method in the framework library, and some additions for the controller.php in order to handle sessions better.
This commit is contained in:
154
core/c/auth.php
154
core/c/auth.php
@@ -10,48 +10,47 @@ namespace Nibiru;
|
||||
*/
|
||||
class Auth extends Controller implements IAuth
|
||||
{
|
||||
private static $_instance;
|
||||
private static $_instance;
|
||||
|
||||
private $_password_salt = "";
|
||||
private $_username = "";
|
||||
private $_password = "";
|
||||
private $_password_salt = "";
|
||||
private $_username = "";
|
||||
private $_password = "";
|
||||
|
||||
/**
|
||||
* Auth constructor.
|
||||
*/
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_setPasswordSalt();
|
||||
protected function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->_setPasswordSalt();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return View
|
||||
*/
|
||||
public static function getInstance(): View
|
||||
{
|
||||
$className = get_called_class();
|
||||
if( self::$_instance == null )
|
||||
{
|
||||
self::$_instance = new $className();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
public static function getInstance(): View
|
||||
{
|
||||
$className = get_called_class();
|
||||
if( self::$_instance == null )
|
||||
{
|
||||
self::$_instance = new $className();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $login
|
||||
* @param $password
|
||||
* @return bool
|
||||
*/
|
||||
public function auth( $login, $password )
|
||||
{
|
||||
// TODO: Implement auth($username, $password) method.
|
||||
public function auth( $login, $password ): bool
|
||||
{
|
||||
// TODO: Implement auth($username, $password) method.
|
||||
$this->_setPassword($password);
|
||||
$this->_setUsername($login);
|
||||
|
||||
if(!array_key_exists('auth', $_SESSION))
|
||||
{
|
||||
if(!array_key_exists('auth', $_SESSION) || $_SESSION['auth'] == null)
|
||||
{
|
||||
$user_password = Pdo::query("SELECT user_account_active, DES_DECRYPT(user_pass, '".Config::getInstance()->getConfig()[IView::NIBIRU_SECURITY]["password_hash"]."') AS pass, user_id FROM user WHERE user_login = '".$login."';");
|
||||
if( $user_password["pass"] == $password && $user_password['user_account_active'] == 1 )
|
||||
{
|
||||
@@ -65,58 +64,69 @@ class Auth extends Controller implements IAuth
|
||||
];
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if($_SESSION['auth']['login'] == $login)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getPasswordSalt()
|
||||
{
|
||||
return $this->_password_salt;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getPasswordSalt()
|
||||
{
|
||||
return $this->_password_salt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password_salt
|
||||
*/
|
||||
private function _setPasswordSalt( )
|
||||
{
|
||||
$this->_password_salt = $this->getConfig()[self::NIBIRU_SECURITY];
|
||||
}
|
||||
/**
|
||||
* @param string $password_salt
|
||||
*/
|
||||
private function _setPasswordSalt( )
|
||||
{
|
||||
$this->_password_salt = $this->getConfig()[self::NIBIRU_SECURITY];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getUsername()
|
||||
{
|
||||
return $this->_username;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getUsername()
|
||||
{
|
||||
return $this->_username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $username
|
||||
*/
|
||||
private function _setUsername( $username )
|
||||
{
|
||||
$this->_username = $username;
|
||||
}
|
||||
/**
|
||||
* @param string $username
|
||||
*/
|
||||
private function _setUsername( $username )
|
||||
{
|
||||
$this->_username = $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getPassword()
|
||||
{
|
||||
return $this->_password;
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getPassword()
|
||||
{
|
||||
return $this->_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $password
|
||||
*/
|
||||
private function _setPassword( $password )
|
||||
{
|
||||
$this->_password = $password;
|
||||
}
|
||||
/**
|
||||
* @param string $password
|
||||
*/
|
||||
private function _setPassword( $password )
|
||||
{
|
||||
$this->_password = $password;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user