title: CodeIgniter login system using md5()
body: <p>I am new in <strong>CodeIgniter</strong> and using <strong>CodeIgniter_2.1.3</strong>. I am following <strong>NETTUTS CodeIgniter</strong> tutorial. I want to develop a login system with codeIgniter which works well without <strong>md5()</strong> function [<strong>without encrypted password</strong>] . Then I create new table with encrypted password using <strong>md5()</strong> function. Then login code doesn't work. My code is ::</p>
  
  <p><strong>view/login_form.php</strong></p>
  
  <pre><code>&lt;?php   
        // form design       
  
       echo form_open("login/validate") . "&lt;br/&gt;";    
       echo form_input("username", "Username") . "&lt;br/&gt; &lt;br/&gt;";
       echo form_password("password", "password") . "&lt;br/&gt; &lt;br/&gt;";
       echo form_submit("submit", "Login") . "&lt;Br/&gt; &lt;Br/&gt;";
  
       echo anchor("login/sign_up", "Create Account"); 
  
   ?&gt;
  </code></pre>
  
  <p><strong>controllers/login.php</strong></p>
  
  <pre><code> &lt;?php
       class Login extends CI_Controller {
  
          function index() {   // function of loading login page
             $data['main_content'] = "login_form";   // name of login page
  
             $this-&gt;load-&gt;view("includes/templet", $data);  
          }
  
      function validate() {   // form validation          
          $this-&gt;load-&gt;model("membership_model");    // load "membership_model" 
          $query = $this-&gt;membership_model-&gt;validate_user();   // check validation
  
          if( $query )  {     // if data found
              $data = array(  // value which is to be inserted into session
                  "username" =&gt; $this-&gt;input-&gt;post("username"),
                  "is_logged_in" =&gt; true
              );
  
              $this-&gt;session-&gt;set_userdata($data);  // insert value into session
              redirect("site/members_area");   // go to predefined page
          }
          else {
              // if data not found then go to login_form page
              $this-&gt;index();
          }  
      }
  
      // create account  
      function sign_up() {
          $data['main_content'] = "sign_up";
  
          $this-&gt;load-&gt;view("includes/templet", $data);
      }
  
      // insert data into database
      function create_member()  {
  
          $this-&gt;load-&gt;library("form_validation");  // load form_validation library
  
          $this-&gt;form_validation-&gt;set_rules("username", "Username", "trim|required");
          $this-&gt;form_validation-&gt;set_rules("password", "Enter Password", "trim|required|min_length[4]|max_length[32]");
          $this-&gt;form_validation-&gt;set_rules("re_password", "Confirm password", "trim|required|matches[password]");
  
          $this-&gt;form_validation-&gt;set_rules("email", "Email Address", "trim|required|valid_email");
  
          if(  $this-&gt;form_validation-&gt;run() == FALSE )  {
              $this-&gt;load-&gt;view("sign_up");
          }
          else {
              $this-&gt;load-&gt;model("membership_model");
  
              if( $query =  $this-&gt;membership_model-&gt;create_member() )  {
                 // redirect("site/members_area");
                  $data['main_content'] = "signup_success";
  
                  $this-&gt;load-&gt;view("includes/templet", $data);
              }
              else {
                  $this-&gt;load-&gt;view("sign_up");
              }
          }
        }
      }
  
   ?&gt;
  </code></pre>
  
  <p><strong>model/membership_model</strong></p>
  
  <pre><code> &lt;?php   
  
       class Membership_model extends CI_Model {
          function validate_user() {
             $this-&gt;db-&gt;where('username', $this-&gt;input-&gt;post('username'));
             $this-&gt;db-&gt;where('password', md5($this-&gt;input-&gt;post('password')));
  
             $query = $this-&gt;db-&gt;get("user");
  
             if( $query-&gt;num_rows == 1 )  {
                return true;
             }
         }
  
         function create_member()  {
            $new_member_insert_data = array(                 
                'username' =&gt; $this-&gt;input-&gt;post("username"),
                'password' =&gt; md5($this-&gt;input-&gt;post("password")),
                'email'    =&gt; $this-&gt;input-&gt;post("email")                 
            );
  
            $insert = $this-&gt;db-&gt;insert("user", $new_member_insert_data);
  
            return true;
        }
     }     
  
   ?&gt;
  </code></pre>