title: Set password to postfix email users stored in mysql by php
body: <p>I am developing a server control panel, but I haven't been able to set correctly the user password in the mysql database.</p>
  
  <p>The mysql query used to store the password is the following:</p>
  
  <pre><code>ENCRYPT('firstpassword', CONCAT('$6$', SUBSTRING(SHA(RAND()), -16)))
  </code></pre>
  
  <p>Yet, I haven't been able to replicate the result in php (of cource, using a static salt): they just don't match.</p>
  
  <p>Here's the php code I have been working with:</p>
  
  <pre><code>$salt = '1234567890123456';
  $password = 'hello';
  $hexhash = hash('sha512', '$6$'. $salt);
  // bda6a11cc3aa00b8fe46f0559e86b3e4be3a6646f7dca2df29da1db86cfd7fc0ceb9ca076d16f0296b82e120170f08e049f607cc6e2d7328976f8cb4e8cacf98
  $binhash = hex2bin($hexhash);
  $hash = base64_encode($binhash);
  // vaahHMOqALj+RvBVnoaz5L46Zkb33KLfKdoduGz9f8DOucoHbRbwKWuC4SAXDwjgSfYHzG4tcyiXb4y06MrPmA==
  </code></pre>
  
  <p>The password instead should be just <code>12NKz5XM5JeKI</code>.
  Any clues about why do the mysql and php implementations differ?</p>