Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public function login(){
  2. $data['title'] = 'Masuk';
  3.  
  4.  
  5. $this->form_validation->set_rules('username','Username','required');
  6.  
  7. $this->form_validation->set_rules('password','Password','required');
  8.  
  9.  
  10. if($this->form_validation->run() === FALSE){
  11. $this->load->view('templates/header');
  12. $this->load->view('users/login', $data);
  13. $this->load->view('templates/footer');
  14.  
  15. }else{
  16.  
  17. // get username
  18.  
  19. $username = $this->input->post('username');
  20. // get and encrypt the password
  21. $password = md5($this->input->post('password'));
  22.  
  23. // LOgin User
  24. $user_id = $this->user_model->login($username,$password);
  25.  
  26. if($user_id){
  27. // create session
  28. $user_data = array(
  29. 'user_id' => $user_id,
  30. 'username' => $username,
  31. 'logged_in' => true
  32. );
  33.  
  34. $this->session->set_userdata($user_data);
  35. // set message
  36.  
  37. $this->session->set_flashdata('user_loggedin','Anda sekarang sudah login');
  38.  
  39. redirect('surat_masuk');
  40.  
  41. }else{
  42.  
  43. // Set message
  44.  
  45. if (isset($_SESSION['auth'])) {
  46. //jika user gagal masuk selama 3x atau lebih
  47. {
  48.  
  49. if ($_SESSION['auth']>2 || $_SESSION['auth']==2) {
  50. //set nilai session 'auth' ke 4
  51.  
  52. $_SESSION['auth']=3;
  53. //jalankan function blokir user
  54. echo "<h1>ANDA TERBLOKIR</h1>";
  55. die();
  56. }
  57.  
  58. }
  59. }
  60. $this->session->set_flashdata('login_failed','Anda gagal login');
  61.  
  62.  
  63. redirect('');
  64. }
  65.  
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement