Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. LOGIN CONTROLLER
  2. -----------------------------------------------------------------------------------
  3. public function login()
  4.  
  5. {
  6.  
  7. if(isset($_POST['login_btn'])){
  8.  
  9. $username = $_POST['userid'];
  10. $password = $_POST['psw'];
  11. $this->load->model('user_model');
  12. $fetch = $this->user_model->login_user($username, $password);
  13.  
  14. if($fetch){
  15.  
  16. $this->welcome();
  17. }else{
  18. $this->load->view('login');
  19. }
  20.  
  21. }else
  22. $this->load->view('login');
  23.  
  24.  
  25. /*
  26. */
  27. }
  28.  
  29. ------------------------------------------
  30. LOGIN MODEL
  31. -----------------------------------------
  32. public function login_user($username, $password){
  33.  
  34. $user = $username;
  35. $this->db->select('user_id, password, username');
  36. $this->db->from('user');
  37. $this->db->where('username', $username);
  38. $query = $this->db->get();
  39.  
  40. $res = $query->row_array();
  41. $result = password_verify($password, $res['password']);
  42. if($query -> num_rows() == 1){
  43. if(password_verify($password, $res['password'])){
  44. $_SESSION['userid'] = $res['username'];
  45. $_SESSION['logged'] = true;
  46. return 1;
  47. }
  48. else{
  49. $_SESSION['message'] = "Username/Password combination doesn't match.";
  50. return 0;
  51. }
  52. }else{
  53.  
  54. $_SESSION['message'] = "Account doesn't exist.";
  55. return 0;
  56. }
  57.  
  58. }
  59.  
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement