title: How to generate .htpasswd under PHP
body: <p>Im trying to generate long htpasswd file with a lot of users (100+).</p>
  
  <p>My DirectAdmin panel on linux server generates htpasswd file with password hashes starting with $1$.</p>
  
  <p>I tried something like this:</p>
  
  <pre><code>function random_salt($length = 9) // 9 characters and $1$ = 12 characters
  {      
      $chars = 'bcdfghjklmnprstvwxzaeiou';
  
      for ($p = 0; $p &lt; $length; $p++)
      {
          $result .= ($p%2) ? $chars[mt_rand(19, 23)] : $chars[mt_rand(0, 18)];
      }
  
      return $result;
  }
  
  echo crypt($myplainpassword, "$1$".random_salt());
  </code></pre>
  
  <p>It produces hash which starts with $1$, but server doesnt let me in. My passwords are 4-digit random "pin codes" generated in excel. Examples:</p>
  
  <p>1215
  5325
  6261</p>
  
  <p>What im doing wrong?</p>