Advertisement
Guest User

Untitled

a guest
Oct 31st, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. //controller
  2. public function password_check($str)
  3. {
  4. if (!preg_match('#[0-9]#', $str) && preg_match('#[a-zA-Z]#', $str)) {
  5. return FALSE;
  6. }
  7. return TRUE;
  8. }
  9.  
  10. public function str_check($str)
  11. {
  12. if (!preg_match("/^[a-zA-Z ]*$/",$str)) {
  13. return FALSE;
  14. }
  15. return TRUE;
  16. }
  17. function loginAction(){
  18. $username = $this->input->post('username');
  19. $password = $this->input->post('password');
  20.  
  21. $this->form_validation->set_rules('username', 'Username', 'trim|alpha_dash|required|min_length[5]|max_length[18]',
  22. array(
  23. 'min_length' => '%s anda kurang dari 5 karakter',
  24. 'alpha_dash' => '%s anda mengandung karakter yang tidak diizinkan'
  25. )
  26. );
  27. $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]|max_length[20]|callback_password_check',
  28. array(
  29. 'min_length' => '%s anda kurang dari 8 karakter',
  30. 'password_check' => '%s anda harus mengandung huruf dan angka',
  31. 'max_length' => '%s maximal berjumlah 20 karakter'
  32. )
  33. );
  34.  
  35. if ($this->form_validation->run() == FALSE)
  36. {
  37. $this->load->view('login');
  38. }
  39. else
  40. {
  41. $where = array(
  42. 'username' => $username,
  43. 'password' => md5($password)
  44. );
  45.  
  46. $cek = $this->m_login->cek_login("user_pb",$where)->num_rows();
  47. if($cek > 0){
  48. $data_session = array(
  49. 'nama' => $username,
  50. 'status' => "login"
  51. );
  52.  
  53. $this->session->set_userdata($data_session);
  54.  
  55. redirect(base_url("admin/admin_page"));
  56. }else{
  57. print "<script type=\"text/javascript\">alert('Username atau password salah!');</script>";
  58. $this->load->view('login');
  59. }
  60. }
  61. }
  62.  
  63. //models
  64. function cek_login($table,$where){
  65. return $this->db->get_where($table,$where);
  66. }
  67.  
  68. //views
  69. <form method="post" action="<?php echo base_url('admin/loginAction'); ?>">
  70. <fieldset>
  71. <div class="form-group">
  72. <!--input class="form-control" placeholder="Username" name="email" type="email" autofocus-->
  73. <h6 style="font-size: 10px; margin-top: 10px; margin-bottom: 2px"><?php echo form_error('username'); ?></h6>
  74. <input type="text" name="username" maxlength="20" minlength="6" value="<?php echo set_value('username'); ?>" placeholder="username" class="form-control" required>
  75. </div>
  76. <div class="form-group">
  77. <!--input class="form-control" placeholder="Password" name="password" type="password" value=""-->
  78. <h6 style="font-size: 10px; margin-top: 10px; margin-bottom: 2px"><?php echo form_error('password'); ?></h6>
  79. <input type="password" name="password" value="<?php echo set_value('password'); ?>" minlength="8" maxlength="36" placeholder="password" class="form-control" required>
  80. </div>
  81. <div class="checkbox">
  82. <label>
  83. <input name="remember" type="checkbox" value="Remember Me">Remember Me
  84. </label>
  85. </div>
  86. <!-- Change this to a button or input when using this as a form -->
  87. <button type="submit" style="font-family:baloo bhaijaan" value="login" class="btn btn-lg btn-success btn-block">Masuk</button>
  88. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement