Advertisement
Guest User

Untitled

a guest
Aug 1st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. class Login extends CI_Controller {
  3.  
  4.  
  5. public function __construct(){
  6. parent::__construct();
  7. $this->load->library('form_validation');
  8. $this->load->model('users_model','um');
  9. $this->load->library('session');
  10.  
  11. if($this->session->userdata('loggedIn')){
  12. redirect('homepage');
  13. }
  14. }
  15.  
  16.  
  17. public function check_database($password){
  18. $username = $this->input->post('username');
  19. $result = $this->um->login($username, $password);
  20. if($result){
  21. $sess_array = array();
  22. foreach($result as $row){
  23. $sess_array = array(
  24. 'id'=>$row->id,
  25. 'username'=>$row->username
  26. );
  27. $this->session->set_userdata('loggedIn',$sess_array);
  28. }
  29. return true;
  30. }else{
  31. $this->form_validation->set_message('check_database', 'Invalid Username or Password.');
  32. return false;
  33. }
  34. }
  35.  
  36. public function verifyLogin(){
  37. $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
  38. $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
  39. if($this->form_validation->run() == FALSE){
  40. $this->data['title'] = 'Login';
  41.  
  42. $this->load->view('templates/header',$this->data);
  43. $this->load->view('pages/login');
  44. $this->load->view('templates/footer');
  45. }else{
  46. //redirect('homepage', 'refresh');
  47. redirect('homepage');
  48. }
  49.  
  50. }
  51.  
  52. public function index(){
  53. $this->data['title'] = 'Login ';
  54.  
  55. $this->load->view('templates/header', $this->data);
  56. $this->load->view('pages/login');
  57. $this->load->view('templates/footer');
  58. }
  59. }
  60.  
  61. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  62.  
  63. class Users_model extends CI_Model {
  64. public function login($username, $password){
  65. $sha_password = sha1($password);
  66. $this->db->select('
  67. users.id,
  68. users.username,
  69. users.email,
  70. users.password')
  71. ->from('users')
  72. ->where('username', $username)
  73. ->where('password', $sha_password);
  74. $query = $this->db->get();
  75. if($query->num_rows() == 1){
  76. return $query->result();
  77. }else{
  78. return false;
  79. }
  80. }
  81. }
  82.  
  83. $this->db->select('
  84. users.id,
  85. users.username,
  86. users.email,
  87. users.password')
  88. ->from('users')
  89. ->where("(users.email = '$username' OR users.username = '$username')")
  90. ->where('password', $sha_password);
  91.  
  92. $this->db->from('users')
  93. ->where("(email = '$username' OR mobile = '$username')")
  94. ->where('password', $data['password'])
  95. ->get();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement