PhpSnip.com

User Stats

Make .htpasswd

If you are making a admin tool for your site you can add all the users into a table called e.g. "users" and automaticaly generate a .htpasswd file from it. This function uses MD5 encryption.

Info

 Download  View Source (print view)
 Rating : 4.7  Views : 3747

Source Code ( 28 lines )

function makehtaccess() {
  global $Cfg;
  connect();
  $users = mysql_query("select username,pass from users where access > '0'") or die ("Can't get users (makehtaccess)");
  $num = mysql_numrows($users);
  $t = 0;
  if ($num != 0) {
    $f = fopen(".htpasswd", "w+");
    while ($num>$t) {
          unset($seed);
	  # generate random seed
	  $all = explode( " ",  
        "a b c d e f g h i j k l m n o p q r s t u v w x y z " 
      . "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z " 
  	  . "0 1 2 3 4 5 6 7 8 9");
      for($i=0;$i<9;$i++) { 
        srand((double)microtime()*1000000); 
        $randy = rand(0, 61); 
        $seed .= $all[$randy];
      }
      $username = mysql_result($users,$t,"username");
      $password = mysql_result($users,$t,"pass");
      $crypt = crypt($password, "$1$$seed");
      fputs($f,"$username:$cryptn");
      $t++;
    }
  }
}

Search

Subscribe

  Rss Feeds

Sponsors

Advertise