Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Login extends CI_Controller
- {
- public function index()
- {
- if(!$this->session->userdata('loggedin'))
- {
- $this->load->view('login');
- }
- else
- {
- redirect('homepage');
- }
- }
- public function authentication()
- {
- $this->load->model('login_model', 'user');
- $username = $this->input->post('Username');
- $password = $this->input->post('Password');
- $sha_pass = sha1(strtoupper($password));
- $this->user->Auth($username, $sha_pass);
- }
- public function logout()
- {
- $this->load->model('login_model', 'user');
- $this->user->LogOut();
- }
- }
- ################# MODEL ###########################
- <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
- class Login_model extends CI_Model
- {
- function __construct()
- {
- parent::__construct();
- }
- function Auth($username, $password)
- {
- if($this->DBAuth($username, $password))
- {
- $data = array(
- 'username' => $username,
- 'password' => $password,
- 'loggedin' => TRUE
- );
- $this->session->set_userdata($data);
- redirect('homepage');
- }
- else
- {
- echo 'Invalid Password';
- }
- }
- function DBAuth($username, $password)
- {
- $sha_pass = sha1(strtoupper($password));
- $query = $this->db->select('username, password')->from('users')->where('username', $username)->where('password', $sha_pass)->get();
- if($query->num_rows() > 0)
- return true;
- else
- return false;
- }
- function LogOut()
- {
- $this->session->sess_destroy();
- redirect('login');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement