title: hash() vs. crypt() function comparison
body: <p>I'm currently implementing a login system. I want to store the password and the salt in a database. Now I found out that there is a <code>hash()</code> and a <code>crypt()</code> function which seems to do the same (valid for SHA512).</p>
  
  <p><code>hash()</code> is newer and seems to support more hashing alogrithms than <code>crypt()</code>. Or there any other differences I should know/care about?</p>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>function generatePasswordHash($password){
      $salt = base64_encode(mcrypt_create_iv(8));
      $calculatedPasswordHash = crypt($password, '$1$' . $salt . '$');
  
      return $calculatedPasswordHash;
  }
  </code></pre>
  
  <p>The result looks like <code>$1$Qh6ByGJ9$zLn3yq62egvmc9D7SzA2u.</code></p>
  
  <p>Here my password checking function:</p>
  
  <pre><code>function checkLoginData($username, $password){
      global $db;
  
      $sql = "SELECT * FROM users WHERE username = :username";
      $result = $db-&gt;ExecuteQuery($sql, array("username"=&gt;$username));
  
      if(!empty($result)){
          $result = $result[0];
          $savedPasswordHash = $result['password'];
          $splitted = explode("$", $savedPasswordHash);
          $salt = $splitted[2];
          $calculatedPasswordHash = crypt($password, '$1$' . $salt . '$');
  
          if($savedPasswordHash === $calculatedPasswordHash){
              return true;
          }
      }
  
      return false;
  }
  </code></pre>