title: Password-recovery expire time in PHP
body: <p>I'm writing a simple password-recovery function for the website I'm developing and I was wondering about the expire time.</p>
  
  <p>Getting to the point, I want to add an expire time of around 48h for the reset password link I'm gonna send. Do I have to create a new column to store the current time and check it out some time later to see if its still valid, or is there a simpler way?</p>
  
  <p>That's my code so far:</p>
  
  <pre><code>public function forgotPass($email) {
      $bd = new Bd();
      $conn = $bd-&gt;connect();
      $stt = $conn-&gt;prepare("SELECT * FROM Users where email=?");
      $stt-&gt; bind_param("s",$email);
      $stt-&gt; execute();
      $result = $stt-&gt;get_result();
      if (mysqli_num_rows($result) == 1) {
          $stt = $conn-&gt;prepare("INSERT INTO Users(recovery) VALUES(?)");
          $recovery = $this-&gt;randHash(8);
  
          if (!$recovery)
              return false;
  
          $stt-&gt; bind_param("s",$recovery);
          $stt-&gt; execute();
      }
  }
  </code></pre>
  
  <p>and here's my <code>randHash</code> code:</p>
  
  <pre><code>private static function randHash($lenght) {
      if (!filter_var($lenght, FILTER_VALIDATE_INT)) {
          return false;
      }   
      $allowed = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      $max = strlen($allowed) - 1;
      for ($i=1;$i&lt;=$lenght;$i++) {
          $hash .= $allowed[mt_rand(0, $max)];
      }
      return $hash;
  }
  </code></pre>