Advertisement
Guest User

Untitled

a guest
Aug 10th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.37 KB | None | 0 0
  1.     public function index() {
  2.        
  3.         $this->load->view('layout/html_header.php'); //Def
  4.         $this->load->view('layout/page_header.php'); //Def
  5.        
  6.         $this->load->library('form_validation');
  7.         $this->load->view('home.php');
  8.        
  9.         $this->load->view('layout/page_footer.php'); //Def
  10.         $this->load->view('layout/html_footer.php'); //Def
  11.        
  12.     }
  13.    
  14.     public function login() {
  15.        
  16.         $this->load->view('layout/html_header.php'); //Def
  17.         $this->load->view('layout/page_header.php'); //Def
  18.        
  19.         $this->load->library('form_validation');       
  20.        
  21.         $this->form_validation->set_rules('user', 'seu usuário', 'required');
  22.         $this->form_validation->set_rules('pass', 'sua senha', 'required');    
  23.        
  24.         $this->form_validation->set_error_delimiters('<p class="error">', '</p>');
  25.         $this->form_validation->set_message('required', 'Preencha %s corretamente.');
  26.         $this->form_validation->set_message('checkPass', 'Os dados de login inseridos estão incorretos.');        
  27.        
  28.        
  29.         if ($this->form_validation->run() == false) {
  30.             $this->load->view('home');
  31.         } else {
  32.            
  33.             $userip = $_SERVER['REMOTE_ADDR'];
  34.            
  35.             $query = $this->db->get_where('hackjump', array('ip' => $userip));
  36.             $rows = $query->num_rows();
  37.            
  38.             if ($rows != 0) {
  39.                 $gpass = false;
  40.             } else {
  41.                 $gpass = true;
  42.             }
  43.            
  44.             if (!$gpass) {
  45.                
  46.                 $row = $query->row(1);
  47.                 $tries = $row->tries;
  48.                 $time = $row->time;
  49.                
  50.                 if ($tries == 3) {
  51.                    
  52.                     $mustTime = $time + 7200;
  53.                    
  54.                     if ($time > $mustTime) {
  55.                         $this->db->delete('hackjump', array('ip' => $userip));
  56.                         $gpass = true;
  57.                     } else {
  58.                         $gpass = false;
  59.                     }
  60.                                        
  61.                 } else {
  62.                     $gpass = true;
  63.                 }
  64.                
  65.             }
  66.            
  67.             if ($gpass) {
  68.                
  69.                 $user = $this->input->post('user');
  70.                 $pass = md5($this->input->post('pass'));   
  71.            
  72.                 $query = $this->db->get_where('users', array('name' => $user, 'pass' => $pass));
  73.                
  74.                 if ($query->num_rows()) {
  75.                     //PASSOU!
  76.                    
  77.                     $this->load->view('fhome');
  78.                     echo "PASSOU!";
  79.                                            
  80.                 } else {
  81.                    
  82.                     $query = $this->db->get_where('hackjump', array('ip' => $userip));
  83.                     $rows = $query->num_rows();
  84.            
  85.                     if ($rows != 0) {
  86.                        
  87.                         $row = $query->row(1);
  88.                         $gtime = $row->time;
  89.                         $btime = $gtime + 7200;
  90.                         $tries = $row->tries;
  91.                         $ntries = $tries + 1;                      
  92.                         $attTime = time();
  93.                        
  94.                         if ($attTime > $btime) {
  95.                             $this->db->delete('hackjump', array('ip' => $userip));  
  96.                             $this->db->insert('hackjump', array('ip' => $userip, 'time' => $attTime, 'tries' => '1'));
  97.                         } else {
  98.                             $this->db->update('hackjump', array('tries' => $ntries, 'time' => $attTime), array('ip' => $userip));
  99.                         }
  100.                        
  101.                     } else {
  102.                         $attTime = time();
  103.                         $this->db->insert('hackjump', array('ip' => $userip, 'time' => $attTime, 'tries' => '1'));
  104.                     }
  105.                    
  106.                     $data['passError'] = "Nome de usuário ou senha incorretos.<br />Se você errar o login 3 vezes o seu IP ficará bloqueado por 2 horas.";              
  107.                     $this->load->view('home', $data);
  108.                 }              
  109.                
  110.             } else {
  111.                 $data['passError'] = "Você errou  o login 3 vezes.<br />O seu IP está bloqueado por enquanto, tente novamente mais tarde ou contate o webmaster.";               
  112.                 $this->load->view('home', $data);
  113.             }                              
  114.            
  115.         }
  116.        
  117.         $this->load->view('layout/page_footer.php'); //Def
  118.         $this->load->view('layout/html_footer.php'); //Def
  119.        
  120.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement