title: How to decrypt md5 passwords in php with substr?
body: <p>I am sharing my 2 file's code.for insert username and passwords and to retrieve data.  My scenario is something different.  if username :
  <strong>abc</strong> and password: <strong>123456789</strong></p>
  
  <p><strong>on login screen user have to enter only 3 digits from his password.But that will be random numbers from his password.</strong> if now system will ask me for 1st,3rd and 9th digit from password.after reload page it will change randomly. it will display 2nd,5th and 4th etc etc.</p>
  
  <p>I am done this task earlier with my code. but now i am thinking to insert password with md5 encryption method.</p>
  
  <p>I am stuck here if i used md5 for encryption then how to retrive password.</p>
  
  <p>insert.php :</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form action="" method="post"&gt;
          &lt;label&gt;username&lt;/label&gt;
          &lt;input type="text" name="username"&gt;
          &lt;label&gt;pin&lt;/label&gt;
          &lt;input type="password" name="pin"&gt;
          &lt;label&gt;password&lt;/label&gt;
          &lt;input type="password" name="password"&gt;
          &lt;button name="submit"&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php
  include 'conn.php';
  if (isset($_POST['submit'])) 
  {
      $name = $_POST['username']; 
      $pass = md5($_POST['password']);
  
      $sql = mysqli_query($conn,'INSERT INTO `emp`(`name`, `pass`) VALUES ("'.$name.'","'.$pass.'")');
      if ($sql&gt;0) 
      {
          header('Location: index.php');  
      }
  }
  ?&gt;
  </code></pre>
  
  <p>index.php:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  include 'conn.php';
  if (isset($_POST['submit'])) {
      $name = $_POST['username'];    
      $pass1 = $_POST['pass1'];
      $pass2 = $_POST['pass2'];
      $pass3 = $_POST['pass3'];
  
      $char1 = $_POST['char1'];
      $char2 = $_POST['char2'];
      $char3 = $_POST['char3'];
  
      $sql = 'SELECT name,pass,pin from `emp` '
              . 'where `name` = "'.$name.'" '
              . 'AND SUBSTR(pass, '.($char1).', 1) = \''.$pass1.'\' '
              . 'AND SUBSTR(pass, '.($char2).', 1) = \''.$pass2.'\' ' 
              . 'AND SUBSTR(pass, '.($char3).', 1) = \''.$pass3.'\' ';        
  
  
      $sql = mysqli_query($conn,$sql);
      $data = mysqli_fetch_assoc($sql);
      if ($data) 
      {
  
          echo 'success';
      }
      else
      {
          echo 'Fail';
      }
  
  }
  
  // generate unique, not equal numbers
  $char_pos = range(1, 9);
  shuffle($char_pos);
  $char_pos = array_slice($char_pos, 0, 3);
  sort($char_pos);
  ?&gt;
  &lt;form action="" method="post"&gt;
      &lt;input type="hidden" name="char1" value="&lt;?php echo $char_pos[0]; ?&gt;"&gt;
      &lt;input type="hidden" name="char2" value="&lt;?php echo $char_pos[1]; ?&gt;"&gt;
      &lt;input type="hidden" name="char3" value="&lt;?php echo $char_pos[2]; ?&gt;"&gt;    
      Username:
       &lt;input type="text" name="username" value=""&gt;    
      Password:
       &lt;input type="password" class="inputs" maxlength="1" name="pass1" placeholder='&lt;?php echo $char_pos[0]; ?&gt;st' value=""&gt;
       &lt;input type="password" class="inputs" maxlength="1" name="pass2" placeholder='&lt;?php echo $char_pos[1]; ?&gt;th' value=""&gt;
       &lt;input type="password" class="inputs" maxlength="1" name="pass3" placeholder='&lt;?php echo $char_pos[2]; ?&gt;th' value=""&gt;
       &lt;button name="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      $(".inputs").keyup(function () {
          if (this.value.length == this.maxLength) {
            $(this).next('.inputs').focus();
          }
      });
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>