المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : How to create Auto generate .htpasswd file



bahattab
05-12-2009, 08:03 PM
How to create Auto generate .htpasswd file



This php script reads a MySQL database, encrypts the passwords and writes an htpasswd file. Using this script you can maintain a database of users and generate an .htpasswd file from the database.

You can download (http://tips-scripts.com/pass_gen.txt) this script as a .txt file. Remember to rename the file as a .php file.





- - Start Script Here - -
<?php
$filename = "your htpasswd file path goes here"; // your htpasswd file name - complete unix path - or relative to this script
$host="host"; // database host address
$dbuser="user"; // database user name
$dbpswd="password"; // database password
$mysqldb="db_name"; // name of database
$table="passwd_table"; // name of table
// modify the above lines for your environment
mysql_connect("$host", "$dbuser", "$dbpswd");
mysql_select_db ("$mysqldb");
$query = mysql_query("SELECT * FROM $table");
while ($row = mysql_fetch_array($query)) {
$user = $row['user'];
$pass = $row['password'];
$encrypted = crypt($pass);
$record .= "$user:$encrypted\r\n";
}
file_put_contents($filename,$record);
?>
- - End Script Here - -






http://tips-scripts.com/pass_gen