public function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//query the database
$result = $this->user_model->login($username, $password);
if ($result) {
$this->session->set_userdata([
'id' => $result->user_id,
'username' => $result->user_name,
'logged_in' => true,
'encryption_key' => $this->generate_encryption_key($password)
]);
return true;
} else {
return false;
}
}
public function __construct()
{
parent::__construct();
$this->load->model('user_model', '', true);
$this->lang->load('admin');
}
public function index()
{
//This method will have the credentials validation
$this->load->library('form_validation');
if ($this->form_validation->run('login') === false) {
//Field validation failed. User redirected to login page
$this->load->view('admin/login', ['username' => $this->input->post('username')]);
} else {
//Go to private area
redirect('admin/dashboard', 'refresh');
}
}
/** @noinspection PhpUnusedPrivateMethodInspection
* @param $password
* @return bool
*/
public function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//query the database
$result = $this->user_model->login($username, $password);
if ($result) {
$this->session->set_userdata([
'id' => $result->user_id,
'username' => $result->user_name,
'logged_in' => true,
'encryption_key' => $this->generate_encryption_key($password)
]);
return true;
} else {
return false;
}
}
private function generate_encryption_key($password)
{
$salted_pass = $password . self::EncryptionKeySalt;
return md5($salted_pass);
}
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Class Login
*/
class Login extends CI_Controller
{
/**
* Отобразить форму входа в систему
*/
public function index()
{
$this->lang->load('admin');
$this->load->helper('form');
$this->load->view('admin/login');
}
/**
* Выйти из системы
*/
public function logout()
{
$this->session->unset_userdata('logged_in');
session_destroy();
redirect('admin/login', 'refresh');
}
}
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Class Dashboard
*
* @property Module_model module_model
*/
class Dashboard extends MX_Controller
{
public function index()
{
if ($this->session->userdata('logged_in')) {
$this->lang->load('admin');
$this->load->model('module_model');
$modules = $this->module_model->get();
$data['panels'] = [];
if ($modules !== false) {
foreach ($modules as $module) {
$panel = Modules::run($module->module_name . '/' . $module->module_name . 'admin/dashboard');
if ($panel !== null) {
if (!array_key_exists('link', $panel)) { // check if there are multiple boards
$data['panels'] = array_merge($data['panels'], $panel);
} else {
$data['panels'][] = $panel;
}
}
}
}
$this->load->view('admin/dashboard', $data);
} else {
redirect('admin/login', 'refresh');
}
}
}
в валидации формы