Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //controller
- public function password_check($str)
- {
- if (!preg_match('#[0-9]#', $str) && preg_match('#[a-zA-Z]#', $str)) {
- return FALSE;
- }
- return TRUE;
- }
- public function str_check($str)
- {
- if (!preg_match("/^[a-zA-Z ]*$/",$str)) {
- return FALSE;
- }
- return TRUE;
- }
- function loginAction(){
- $username = $this->input->post('username');
- $password = $this->input->post('password');
- $this->form_validation->set_rules('username', 'Username', 'trim|alpha_dash|required|min_length[5]|max_length[18]',
- array(
- 'min_length' => '%s anda kurang dari 5 karakter',
- 'alpha_dash' => '%s anda mengandung karakter yang tidak diizinkan'
- )
- );
- $this->form_validation->set_rules('password', 'Password', 'required|min_length[8]|max_length[20]|callback_password_check',
- array(
- 'min_length' => '%s anda kurang dari 8 karakter',
- 'password_check' => '%s anda harus mengandung huruf dan angka',
- 'max_length' => '%s maximal berjumlah 20 karakter'
- )
- );
- if ($this->form_validation->run() == FALSE)
- {
- $this->load->view('login');
- }
- else
- {
- $where = array(
- 'username' => $username,
- 'password' => md5($password)
- );
- $cek = $this->m_login->cek_login("user_pb",$where)->num_rows();
- if($cek > 0){
- $data_session = array(
- 'nama' => $username,
- 'status' => "login"
- );
- $this->session->set_userdata($data_session);
- redirect(base_url("admin/admin_page"));
- }else{
- print "<script type=\"text/javascript\">alert('Username atau password salah!');</script>";
- $this->load->view('login');
- }
- }
- }
- //models
- function cek_login($table,$where){
- return $this->db->get_where($table,$where);
- }
- //views
- <form method="post" action="<?php echo base_url('admin/loginAction'); ?>">
- <fieldset>
- <div class="form-group">
- <!--input class="form-control" placeholder="Username" name="email" type="email" autofocus-->
- <h6 style="font-size: 10px; margin-top: 10px; margin-bottom: 2px"><?php echo form_error('username'); ?></h6>
- <input type="text" name="username" maxlength="20" minlength="6" value="<?php echo set_value('username'); ?>" placeholder="username" class="form-control" required>
- </div>
- <div class="form-group">
- <!--input class="form-control" placeholder="Password" name="password" type="password" value=""-->
- <h6 style="font-size: 10px; margin-top: 10px; margin-bottom: 2px"><?php echo form_error('password'); ?></h6>
- <input type="password" name="password" value="<?php echo set_value('password'); ?>" minlength="8" maxlength="36" placeholder="password" class="form-control" required>
- </div>
- <div class="checkbox">
- <label>
- <input name="remember" type="checkbox" value="Remember Me">Remember Me
- </label>
- </div>
- <!-- Change this to a button or input when using this as a form -->
- <button type="submit" style="font-family:baloo bhaijaan" value="login" class="btn btn-lg btn-success btn-block">Masuk</button>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement