Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function login(){
- $data['title'] = 'Masuk';
- $this->form_validation->set_rules('username','Username','required');
- $this->form_validation->set_rules('password','Password','required');
- if($this->form_validation->run() === FALSE){
- $this->load->view('templates/header');
- $this->load->view('users/login', $data);
- $this->load->view('templates/footer');
- }else{
- // get username
- $username = $this->input->post('username');
- // get and encrypt the password
- $password = md5($this->input->post('password'));
- // LOgin User
- $user_id = $this->user_model->login($username,$password);
- if($user_id){
- // create session
- $user_data = array(
- 'user_id' => $user_id,
- 'username' => $username,
- 'logged_in' => true
- );
- $this->session->set_userdata($user_data);
- // set message
- $this->session->set_flashdata('user_loggedin','Anda sekarang sudah login');
- redirect('surat_masuk');
- }else{
- // Set message
- if (isset($_SESSION['auth'])) {
- //jika user gagal masuk selama 3x atau lebih
- {
- if ($_SESSION['auth']>2 || $_SESSION['auth']==2) {
- //set nilai session 'auth' ke 4
- $_SESSION['auth']=3;
- //jalankan function blokir user
- echo "<h1>ANDA TERBLOKIR</h1>";
- die();
- }
- }
- }
- $this->session->set_flashdata('login_failed','Anda gagal login');
- redirect('');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement