Codeigniter - how to make calculation captcha











up vote
0
down vote

favorite












I wanted to make a calculation captcha, my current captcha is only a text&number input captcha but it is working just that this captcha is kind of hard so i was thinking to make the captcha easier for login, since the view is like this(the image here) which is making the login harder (ignore the userdata for login and focus the line which has captcha on it and please tell me if the code is too long i will try to make it shorter)



Controller



public function index(){
$config = array(
'img_path' => 'captcha_images/',
'img_url' => base_url().'captcha_images/',
'img_width' => '150',
'img_height' => 50,
'word_length' => 8,
'font_size' => 16
);
$captcha = create_captcha($config);

// Unset previous captcha and store new captcha word
$this->session->unset_userdata('captchaCode');
$this->session->set_userdata('captchaCode',$captcha['word']);

// Send captcha image to view
$data['captchaImg'] = $captcha['image'];

$data['tampilan'] = $this->m_model->a('judul')->result();
$this->load->view('login',$data);
}

function aksi_login(){
$data = array('username' => $this->input->post('username', TRUE),
'password' => md5($this->input->post('password', TRUE))
);


$this->load->model('m_model'); // load model_user
$hasil = $this->m_model->cek_user($data);
if ($hasil->num_rows() == 1 && $this->input->post('submit')){
$inputCaptcha = $this->input->post('captcha');
$sessCaptcha = $this->session->userdata('captchaCode');
if($inputCaptcha === $sessCaptcha){
foreach ($hasil->result() as $sess) {
$sess_data['logged_in'] = 'Sudah Login';
$sess_data['id_user'] = $sess->uid;
$sess_data['username'] = $sess->username;
$sess_data['level'] = $sess->level;
$this->session->set_userdata($sess_data);
}


if ($this->session->userdata('level')=='1') {
redirect('admin');
}
elseif ($this->session->userdata('level')=='2') {
redirect('guru');
}
else {
redirect('welcome/salah');
}
}
else{
echo "captcha is wrong";
}
}
}


view



<form action="<?php echo base_url()?>welcome/aksi_login" method="post" class="form">
<h4> Login </h4>

<inputtype="text" name="username" placeholder="username"/>

<input name="password" type="password" placeholder="Password"/>


<a href="<?php echo base_url()?>Welcome" class="refreshCaptcha" ><img src="<?php echo base_url().'asset/foto/refresh.png'; ?>"/></a>
<p id="captImg"><?php echo $captchaImg; ?></p>
<inputtype="text" name="captcha" placeholder="Captcha" />


<input type="submit" name="submit" value="Log in"/>

</form>









share|improve this question


























    up vote
    0
    down vote

    favorite












    I wanted to make a calculation captcha, my current captcha is only a text&number input captcha but it is working just that this captcha is kind of hard so i was thinking to make the captcha easier for login, since the view is like this(the image here) which is making the login harder (ignore the userdata for login and focus the line which has captcha on it and please tell me if the code is too long i will try to make it shorter)



    Controller



    public function index(){
    $config = array(
    'img_path' => 'captcha_images/',
    'img_url' => base_url().'captcha_images/',
    'img_width' => '150',
    'img_height' => 50,
    'word_length' => 8,
    'font_size' => 16
    );
    $captcha = create_captcha($config);

    // Unset previous captcha and store new captcha word
    $this->session->unset_userdata('captchaCode');
    $this->session->set_userdata('captchaCode',$captcha['word']);

    // Send captcha image to view
    $data['captchaImg'] = $captcha['image'];

    $data['tampilan'] = $this->m_model->a('judul')->result();
    $this->load->view('login',$data);
    }

    function aksi_login(){
    $data = array('username' => $this->input->post('username', TRUE),
    'password' => md5($this->input->post('password', TRUE))
    );


    $this->load->model('m_model'); // load model_user
    $hasil = $this->m_model->cek_user($data);
    if ($hasil->num_rows() == 1 && $this->input->post('submit')){
    $inputCaptcha = $this->input->post('captcha');
    $sessCaptcha = $this->session->userdata('captchaCode');
    if($inputCaptcha === $sessCaptcha){
    foreach ($hasil->result() as $sess) {
    $sess_data['logged_in'] = 'Sudah Login';
    $sess_data['id_user'] = $sess->uid;
    $sess_data['username'] = $sess->username;
    $sess_data['level'] = $sess->level;
    $this->session->set_userdata($sess_data);
    }


    if ($this->session->userdata('level')=='1') {
    redirect('admin');
    }
    elseif ($this->session->userdata('level')=='2') {
    redirect('guru');
    }
    else {
    redirect('welcome/salah');
    }
    }
    else{
    echo "captcha is wrong";
    }
    }
    }


    view



    <form action="<?php echo base_url()?>welcome/aksi_login" method="post" class="form">
    <h4> Login </h4>

    <inputtype="text" name="username" placeholder="username"/>

    <input name="password" type="password" placeholder="Password"/>


    <a href="<?php echo base_url()?>Welcome" class="refreshCaptcha" ><img src="<?php echo base_url().'asset/foto/refresh.png'; ?>"/></a>
    <p id="captImg"><?php echo $captchaImg; ?></p>
    <inputtype="text" name="captcha" placeholder="Captcha" />


    <input type="submit" name="submit" value="Log in"/>

    </form>









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I wanted to make a calculation captcha, my current captcha is only a text&number input captcha but it is working just that this captcha is kind of hard so i was thinking to make the captcha easier for login, since the view is like this(the image here) which is making the login harder (ignore the userdata for login and focus the line which has captcha on it and please tell me if the code is too long i will try to make it shorter)



      Controller



      public function index(){
      $config = array(
      'img_path' => 'captcha_images/',
      'img_url' => base_url().'captcha_images/',
      'img_width' => '150',
      'img_height' => 50,
      'word_length' => 8,
      'font_size' => 16
      );
      $captcha = create_captcha($config);

      // Unset previous captcha and store new captcha word
      $this->session->unset_userdata('captchaCode');
      $this->session->set_userdata('captchaCode',$captcha['word']);

      // Send captcha image to view
      $data['captchaImg'] = $captcha['image'];

      $data['tampilan'] = $this->m_model->a('judul')->result();
      $this->load->view('login',$data);
      }

      function aksi_login(){
      $data = array('username' => $this->input->post('username', TRUE),
      'password' => md5($this->input->post('password', TRUE))
      );


      $this->load->model('m_model'); // load model_user
      $hasil = $this->m_model->cek_user($data);
      if ($hasil->num_rows() == 1 && $this->input->post('submit')){
      $inputCaptcha = $this->input->post('captcha');
      $sessCaptcha = $this->session->userdata('captchaCode');
      if($inputCaptcha === $sessCaptcha){
      foreach ($hasil->result() as $sess) {
      $sess_data['logged_in'] = 'Sudah Login';
      $sess_data['id_user'] = $sess->uid;
      $sess_data['username'] = $sess->username;
      $sess_data['level'] = $sess->level;
      $this->session->set_userdata($sess_data);
      }


      if ($this->session->userdata('level')=='1') {
      redirect('admin');
      }
      elseif ($this->session->userdata('level')=='2') {
      redirect('guru');
      }
      else {
      redirect('welcome/salah');
      }
      }
      else{
      echo "captcha is wrong";
      }
      }
      }


      view



      <form action="<?php echo base_url()?>welcome/aksi_login" method="post" class="form">
      <h4> Login </h4>

      <inputtype="text" name="username" placeholder="username"/>

      <input name="password" type="password" placeholder="Password"/>


      <a href="<?php echo base_url()?>Welcome" class="refreshCaptcha" ><img src="<?php echo base_url().'asset/foto/refresh.png'; ?>"/></a>
      <p id="captImg"><?php echo $captchaImg; ?></p>
      <inputtype="text" name="captcha" placeholder="Captcha" />


      <input type="submit" name="submit" value="Log in"/>

      </form>









      share|improve this question













      I wanted to make a calculation captcha, my current captcha is only a text&number input captcha but it is working just that this captcha is kind of hard so i was thinking to make the captcha easier for login, since the view is like this(the image here) which is making the login harder (ignore the userdata for login and focus the line which has captcha on it and please tell me if the code is too long i will try to make it shorter)



      Controller



      public function index(){
      $config = array(
      'img_path' => 'captcha_images/',
      'img_url' => base_url().'captcha_images/',
      'img_width' => '150',
      'img_height' => 50,
      'word_length' => 8,
      'font_size' => 16
      );
      $captcha = create_captcha($config);

      // Unset previous captcha and store new captcha word
      $this->session->unset_userdata('captchaCode');
      $this->session->set_userdata('captchaCode',$captcha['word']);

      // Send captcha image to view
      $data['captchaImg'] = $captcha['image'];

      $data['tampilan'] = $this->m_model->a('judul')->result();
      $this->load->view('login',$data);
      }

      function aksi_login(){
      $data = array('username' => $this->input->post('username', TRUE),
      'password' => md5($this->input->post('password', TRUE))
      );


      $this->load->model('m_model'); // load model_user
      $hasil = $this->m_model->cek_user($data);
      if ($hasil->num_rows() == 1 && $this->input->post('submit')){
      $inputCaptcha = $this->input->post('captcha');
      $sessCaptcha = $this->session->userdata('captchaCode');
      if($inputCaptcha === $sessCaptcha){
      foreach ($hasil->result() as $sess) {
      $sess_data['logged_in'] = 'Sudah Login';
      $sess_data['id_user'] = $sess->uid;
      $sess_data['username'] = $sess->username;
      $sess_data['level'] = $sess->level;
      $this->session->set_userdata($sess_data);
      }


      if ($this->session->userdata('level')=='1') {
      redirect('admin');
      }
      elseif ($this->session->userdata('level')=='2') {
      redirect('guru');
      }
      else {
      redirect('welcome/salah');
      }
      }
      else{
      echo "captcha is wrong";
      }
      }
      }


      view



      <form action="<?php echo base_url()?>welcome/aksi_login" method="post" class="form">
      <h4> Login </h4>

      <inputtype="text" name="username" placeholder="username"/>

      <input name="password" type="password" placeholder="Password"/>


      <a href="<?php echo base_url()?>Welcome" class="refreshCaptcha" ><img src="<?php echo base_url().'asset/foto/refresh.png'; ?>"/></a>
      <p id="captImg"><?php echo $captchaImg; ?></p>
      <inputtype="text" name="captcha" placeholder="Captcha" />


      <input type="submit" name="submit" value="Log in"/>

      </form>






      php codeigniter captcha






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 15 hours ago









      Happy Dog

      74




      74
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You can make a variable 'word_length' => $var and on reCaptcha use a smaller number.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203271%2fcodeigniter-how-to-make-calculation-captcha%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            You can make a variable 'word_length' => $var and on reCaptcha use a smaller number.






            share|improve this answer

























              up vote
              0
              down vote













              You can make a variable 'word_length' => $var and on reCaptcha use a smaller number.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                You can make a variable 'word_length' => $var and on reCaptcha use a smaller number.






                share|improve this answer












                You can make a variable 'word_length' => $var and on reCaptcha use a smaller number.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 12 hours ago









                Sherif Salah

                7414




                7414






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203271%2fcodeigniter-how-to-make-calculation-captcha%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Schultheiß

                    Liste der Kulturdenkmale in Wilsdruff

                    Android Play Services Check