Advertisement
Maretknow

authlogin

Apr 2nd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. function auth(){
  2. if($_POST){
  3.  
  4. $this->load->library('form_validation');
  5. $this->form_validation->set_rules('username', 'Username', 'required|trim|xss_clean');
  6. $this->form_validation->set_rules('password', 'Password', 'required|trim|xss_clean');
  7.  
  8. if($this->form_validation->run() == FALSE){
  9. redirect('');
  10. }
  11.  
  12. $username = $this->input->post('username');
  13. $password = $this->encrypt->sha1($this->input->post('password'));
  14. $level = $this->input->post('level');
  15.  
  16. $temp = $this->model->login("where username = '$username' and password = '$password'
  17. and level = '$level'")->result_array();
  18.  
  19. if($temp != NULL){
  20. $data = array(
  21. 'id' => $temp[0]['id_user'],
  22. 'nama' => $temp[0]['nama'],
  23. 'username' => $temp[0]['username'],
  24. 'password' => $temp[0]['password'],
  25. 'level' => $temp[0]['level'],
  26. );
  27. $this->session->set_userdata('login',$data);
  28. if($data["level"] == "1"){
  29. redirect("admin/dashboard");
  30. }
  31. elseif($data["level"] == "3"){
  32. redirect("admin/dashboard");
  33. }
  34.  
  35. else {
  36. echo "ERROR! 404 Tidak Ada";
  37. }
  38.  
  39. }
  40. else {
  41.  
  42. $error = '
  43. <div class="alert alert-danger alert-dismissable fade in">
  44. <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
  45. <strong>Kesalahan!</strong> Silahkan cek kembali username, password dan level anda.
  46. </div>
  47. ';
  48.  
  49. $this->session->set_flashdata('error', $error);
  50. redirect('login');
  51.  
  52. }
  53. }
  54. else {
  55. redirect('');
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement