Guest User

Untitled

a guest
Oct 31st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3.  
  4. class Admin extends MX_Controller {
  5. function __construct(){
  6. parent::__construct();
  7. $this->load->model('m_login');
  8. $this->load->model('m_profile');
  9. }
  10. public function index()
  11. {
  12. $this->load->view('login');
  13. }
  14. public function loginPage(){
  15. $this->load->view('login');
  16. }
  17. //---validasi login---
  18. function loginAction(){
  19. $username = $this->input->post('username');
  20. $password = $this->input->post('password');
  21.  
  22. $this->form_validation->set_rules('username', 'Username', 'trim|alpha_dash|required|min_length[5]|max_length[18]',
  23. array(
  24. 'min_length' => '%s anda kurang dari 5 karakter',
  25. 'alpha_dash' => '%s anda mengandung karakter yang tidak diizinkan'
  26. )
  27. );
  28. $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]|max_length[20]|callback_password_check',
  29. array(
  30. 'min_length' => '%s anda kurang dari 8 karakter',
  31. 'password_check' => '%s anda harus mengandung huruf dan angka',
  32. 'max_length' => '%s maximal berjumlah 20 karakter'
  33. )
  34. );
  35.  
  36. if ($this->form_validation->run() == FALSE)
  37. {
  38. $this->load->view('login');
  39. }
  40. else
  41. {
  42. $where = array(
  43. 'username' => $username,
  44. 'password' => md5($password)
  45. );
  46.  
  47. $cek = $this->m_login->cek_login("user_pb",$where)->num_rows();
  48. if($cek > 0){
  49. $data_session = array(
  50. 'nama' => $username,
  51. 'status' => "login"
  52. );
  53.  
  54. $this->session->set_userdata($data_session);
  55.  
  56. redirect(base_url("admin/admin_page"));
  57. }else{
  58. print "<script type="text/javascript">alert('Username atau password salah!');</script>";
  59. $this->load->view('login');
  60. }
  61. }
  62. }
  63.  
  64. public function password_check($str)
  65. {
  66. if (preg_match('#[0-9]#', $str) && preg_match('#[a-zA-Z]#', $str)) {
  67. return TRUE;
  68. }
  69. return TRUE;
  70. }
Add Comment
Please, Sign In to add comment