Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2.  
  3. class Login extends CI_Controller
  4. {
  5. public function index()
  6. {
  7. if(!$this->session->userdata('loggedin'))
  8. {
  9. $this->load->view('login');
  10. }
  11. else
  12. {
  13. redirect('homepage');
  14. }
  15. }
  16.  
  17. public function authentication()
  18. {
  19. $this->load->model('login_model', 'user');
  20. $username = $this->input->post('Username');
  21. $password = $this->input->post('Password');
  22. $sha_pass = sha1(strtoupper($password));
  23. $this->user->Auth($username, $sha_pass);
  24. }
  25.  
  26. public function logout()
  27. {
  28. $this->load->model('login_model', 'user');
  29. $this->user->LogOut();
  30. }
  31. }
  32.  
  33.  
  34.  
  35.  
  36. ################# MODEL ###########################
  37. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  38.  
  39. class Login_model extends CI_Model
  40. {
  41. function __construct()
  42. {
  43. parent::__construct();
  44. }
  45.  
  46. function Auth($username, $password)
  47. {
  48. if($this->DBAuth($username, $password))
  49. {
  50. $data = array(
  51. 'username' => $username,
  52. 'password' => $password,
  53. 'loggedin' => TRUE
  54. );
  55. $this->session->set_userdata($data);
  56. redirect('homepage');
  57. }
  58. else
  59. {
  60. echo 'Invalid Password';
  61. }
  62. }
  63.  
  64. function DBAuth($username, $password)
  65. {
  66. $sha_pass = sha1(strtoupper($password));
  67. $query = $this->db->select('username, password')->from('users')->where('username', $username)->where('password', $sha_pass)->get();
  68. if($query->num_rows() > 0)
  69. return true;
  70. else
  71. return false;
  72. }
  73.  
  74. function LogOut()
  75. {
  76. $this->session->sess_destroy();
  77. redirect('login');
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement