Guest User

Untitled

a guest
Dec 10th, 2018
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.50 KB | None | 0 0
  1. public function submit($post_username = NULL, $post_password = NULL)
  2.     {
  3.         $output_error = 'TRUE';
  4.         $output_title = 'Not processed';
  5.         $output_message = 'The request was unprocessed!';
  6.        
  7.         if ($this->users_model->is_logged_in($this->session->userdata('xtr')) === FALSE)
  8.         {
  9.             $data = array();
  10.             $x = 0;
  11.            
  12.             if ($this->input->post()) { $data = $this->input->post(); } else { $x++; }
  13.             if ($this->input->get()) { $data = $this->input->get(); } else { $x++; }
  14.            
  15.             if ($x == 2)
  16.             {
  17.                 if ($this->functions_model->null_check($post_username) === FALSE) { $data['username'] = $post_username; }
  18.                 if ($this->functions_model->null_check($post_password) === FALSE) { $data['password'] = $post_password; }
  19.             }
  20.            
  21.             if (count($data) > 0)
  22.             {
  23.                 $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|strtolower');
  24.                 $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
  25.                
  26.                 if ($this->form_validation->run())
  27.                 {
  28.                     $x = 0;
  29.                     $post_username = $data['username'];
  30.                     $post_password = $data['password'];
  31.                     date_default_timezone_set('GMT');
  32.                     $current_gmt_time = time();
  33.                    
  34.                     $user_data = $this->users_model->get_user_data('', $post_username);
  35.                    
  36.                     if ($user_data !== NULL)
  37.                     {
  38.                         if ($user_data->lock_date !== '0000-00-00 00:00:00')
  39.                         {
  40.                             $output_title = 'Account Locked';
  41.                             $output_message = 'Your account is currently locked due to too many failed login attempts. Please wait the allotted time and you will be able to login again!';
  42.                             $x++;
  43.                         }
  44.                         else
  45.                         {
  46.                             $this->users_model->unlock_user($user_data->user_id);
  47.                             $this->submit($post_username, $post_password);
  48.                             return false;
  49.                         }
  50.                        
  51.                         if ($x == 0)
  52.                         {
  53.                             if ($user_data->user_status_id == '1')
  54.                             {
  55.                                 $output_title = 'Account not verified';
  56.                                 $output_message = 'Sorry you must verify your account before logging in!';
  57.                                 $x++;
  58.                             }
  59.                        
  60.                             if ($user_data->user_status_id == '3')
  61.                             {
  62.                                 $output_title = 'Account Suspended';
  63.                                 $output_message = 'Your account has been suspended!';
  64.                                 $x++;
  65.                             }
  66.                        
  67.                             if ($user_data->user_status_id == '4')
  68.                             {
  69.                                 $output_title = 'Account Banned';
  70.                                 $output_message = 'Your account has been banned!';
  71.                                 $x++;
  72.                             }
  73.                        
  74.                             if ($user_data->user_status_id == '5')
  75.                             {
  76.                                 $output_title = 'Account Deleted';
  77.                                 $output_message = 'Your account has been deleted!';
  78.                                 $x++;
  79.                             }
  80.                        
  81.                             if ($x == 0)
  82.                             {
  83.                                 $regenerated_post_password = $this->functions_model->regenerate_password_hash($post_password, $user_data->password_hash);
  84.                                 $failed_logins = $this->session->userdata('failed_logins');
  85.                            
  86.                                 if ($regenerated_post_password == $user_data->password)
  87.                                 {
  88.                                     $profile_data = $this->users_model->get_profile_data($user_data->user_id);
  89.                                     $this->session->set_userdata('xtr', $user_data->user_id);
  90.                                     $this->session->unset_userdata('failed_logins');
  91.                                     $output_error = 'FALSE';
  92.                                     $output_title = 'Login Success';
  93.                                     $output_message = 'Successful login! Sending you to the dashboard';
  94.                                 }
  95.                                 else
  96.                                 {
  97.                                     if (is_numeric($failed_logins))
  98.                                     {
  99.                                         if ($failed_logins == ((int)$this->config->item('failed_login_limit') - 1))
  100.                                         {
  101.                                             $wait_time = $this->config->item('wait_time');
  102.                                             $wait_time = $current_gmt_time + $wait_time;
  103.                                             $lock_out_date = gmdate('Y-m-d H:i:s', $wait_time);
  104.                                             $this->users_model->lock_out_user($user_data->user_id, $lock_out_date);
  105.                                             $this->functions_model->send_email('maximum_failed_login_attempts_exceeded', $user_data->email_address, $user_data);
  106.                                             $output_title = 'Account Locked';
  107.                                             $output_message = 'Your account is currently locked, we apologize for the inconvienence. You must wait 15 minutes befor eyou can login again! An email was sent to the owner of this account! Forgotten your username or password? <a href="forgotusername">Forgot Username</a> or <a href="forgotpassword">Forgot Password</a>';
  108.                                         }
  109.                                         else
  110.                                         {
  111.                                             $failed_logins++;
  112.                                             $this->session->set_userdata('failed_logins', $failed_logins);
  113.                                             $output_title = 'Incorrect Credentials';
  114.                                             $output_message = 'Incorrect username and password combination!';
  115.                                         }  
  116.                                     }
  117.                                     else
  118.                                     {
  119.                                         $this->session->set_userdata('failed_logins', '1');
  120.                                         $output_title = 'Incorrect Credentials';
  121.                                         $output_message = 'Incorrect username and password combination!';
  122.                                     }  
  123.                                     $time_of_attempt = gmdate('Y-m-d H:i:s');
  124.                                     $this->users_model->increase_login_attempt($this->input->ip_address(), $post_username, $time_of_attempt);
  125.                                 }
  126.                             }
  127.                         }
  128.                     }
  129.                     else
  130.                     {
  131.                         $output_title = 'User not found';
  132.                         $output_message = 'User was not found in the database!';
  133.                     }
  134.                    
  135.                 }
  136.                 else
  137.                 {
  138.                     $output_title = 'Form not submitted';
  139.                     $output_message = validation_errors();
  140.                 }
  141.             }
  142.             else
  143.             {
  144.                 $output_title = 'No data';
  145.                 $output_message = 'There is no data to work with!';
  146.             }
  147.         }
  148.         else
  149.         {
  150.             $output_title = 'Session Available';
  151.             $output_message = 'You are already logged in!';
  152.         }
  153.         echo json_encode(array('error' => $output_error, 'title' => $output_title, 'message' => $output_message));
  154.     }
  155. }
Add Comment
Please, Sign In to add comment