SHARE
TWEET

Untitled

truthsearcher Feb 24th, 2019 28 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. User.php
  2.  
  3. <?php
  4. defined('BASEPATH') OR exit('No direct script access allowed');
  5.  
  6. class User extends CI_Controller{
  7.     public function check_captcha($captcha_input)
  8.     {
  9.         // First, delete old captchas
  10.         $expiration = time() - 7200; // Two hour limit
  11.         $this->db->where('captcha_time < ', $expiration)
  12.                 ->delete('captcha');
  13.  
  14.         // Then see if a captcha exists:
  15.         $sql = 'SELECT COUNT(*) AS count FROM captcha WHERE word = ? AND ip_address = ? AND captcha_time > ?';
  16.         $binds = array($captcha_input, $this->input->ip_address(), $expiration);
  17.         $query = $this->db->query($sql, $binds);
  18.         $row = $query->row();
  19.         if ($row->count == 0){
  20.             $this->form_validation->set_message('check_captcha', 'Captcha Fail');
  21.             return FALSE;
  22.         }else {
  23.             return TRUE;
  24.         }
  25.  
  26.     }
  27.  
  28.     public function register(){  
  29.         $this->form_validation->set_rules('user_name' , 'Username' , 'trim|required|max_length[32]');
  30.         $this->form_validation->set_rules('captcha' , 'Captcha' , 'trim|required|max_length[32]|callback_check_captcha');
  31.         $this->form_validation->set_rules('password', 'Password','trim|required|min_length[5]|max_length[12]');
  32.         $this->form_validation->set_rules('confirm_password', 'Confirm Password','trim|required|min_length[5]|max_length[12]|matches[password]');
  33.         $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
  34.         if ($this->form_validation->run()==FALSE){
  35.         //Captcha code
  36.         $this->load->helper('captcha');
  37.         //Captcha Config
  38.         $vals = array(
  39.             'img_path'      => './captcha',
  40.             'img_url'       => './captcha/',
  41.             'img_width'     => '150',
  42.             'img_height'    => 30,
  43.             'expiration'    => 7200,
  44.             'word_length'   => 8,
  45.             'font_size'     => 16,
  46.             'img_id'        => 'Imageid',
  47.              'font_path'     => '/fonts/Open.ttf',
  48.  
  49.             // White background and border, black text and red grid
  50.             'colors'        => array(
  51.                     'background' => array(255, 255, 255),
  52.                     'border' => array(255, 255, 255),
  53.                     'text' => array(0, 0, 0),
  54.                     'grid' => array(255, 40, 40)
  55.             )
  56.         );
  57.         //Create the Captcha
  58.         $cap = create_captcha($vals);
  59.  
  60.         // Store The Created Captcha in DB for Verification  
  61.         $data = array(
  62.         'captcha_time'  => $cap['time'],
  63.         'ip_address'    => $this->input->ip_address(),
  64.         'word'          => $cap['word']
  65.         );
  66.         $this->register_model->store_captcha($data);
  67.         //Load View
  68.         $data['image']=$cap['image'];
  69.         var_dump($data['image']);exit();
  70.         $this->load->view('templates/header');
  71.         $this->load->view('register' , $data);
  72.         $this->load->view('templates/footer');
  73.         }else {
  74.                   $option=array('cost'=>12);
  75.                   $encrypt_password=password_hash($this->input->post('password'),PASSWORD_BCRYPT,$option);
  76.                   $this->register_model->add_user($encrypt_password);
  77.                   $this->session->set_flashdata('user_registered','You are Successfully Registered and can Log in ');
  78.                   redirect('register/success');
  79.         }
  80.     }
  81.     public function success(){
  82.         $this->load->view('success');
  83.     }
  84. }
  85.  
  86. View (register.php)
  87.  
  88. <div class="col-md-8">    
  89.     <h2>Register</h2><br>
  90.     <?php echo validation_errors(); ?>
  91.     <?php echo form_open("register");
  92.  
  93.     ?>
  94.       <div class="form-group">
  95.         <label>Enter UserID</label>
  96.         <input type="text" class="form-control" name="user_name"  placeholder="Enter Your UserId">
  97.       </div>
  98.       <div class="form-group">
  99.         <label>Enter Your Email</label>
  100.         <input type="email" class="form-control" name="email"  placeholder="Enter Your Email">
  101.       </div>
  102.       <div class="form-group">
  103.         <label>Enter Your Password </label>
  104.         <input type="password" class="form-control" name="password"  placeholder="Enter Password">
  105.       </div>
  106.       <div class="form-group">
  107.             <label>Re-enter Password </label>
  108.             <input type="password" class="form-control" name="confirm_password"  placeholder="Renter Password">
  109.       </div>
  110.       <?php echo $image ; ?>
  111.       <div class="form-group">
  112.             <label>Solve Captcha </label>
  113.             <input type="text" class="form-control" name="captcha" >
  114.       </div>
  115.        <button type="submit" class="btn btn-primary">Submit</button>
  116.       <?php echo form_close();?>
  117. </div>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top