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

مشاهدة النسخة كاملة : How to creat Auto Password Change and Email Notification from .htpasswd useing php



bahattab
05-12-2009, 08:26 PM
Auto Password Change and Email Notification




This script will change your .htpasswd password to a new random password (with encryption) and send an email to notify you of the change. You can run this script automatically using cron at what ever interval you like, or run it manually.

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





- - Start Script Here - -
<?php
$filename = "/XXXXXX/.htpasswd"; // the location of your .htpasswd file
$username = "XXXXXXX"; // the username specified in the .htaccess file
$length = "10"; // length of the password
$emailaddress = "you@yourdomain.com"; // email address
// change nothing below this line
// generate password
$spec_charset = array("!","@","#","$","%","^","&","*","_","+"."?","=");
$chars = array();
unset($pass);
for ($i = 1; $i <= $length; $i++) {
for ($i = 48; $i <= 57; $i++) $chars[] = chr($i); // numbers
for ($i = 65; $i <= 90; $i++) $chars[] = chr($i); // upper
for ($i = 97; $i <= 122; $i++) $chars[] = chr($i); // lower
foreach ($spec_charset as $i) $chars[] = $i; // special
for ($i = 1; $i <= $length; $i++) $pass .= $chars[rand(0,count($chars)-1)];
}
// build & write .htpasswd file
$encrypted = crypt($pass);
$output = "$username:$encrypted\n";
if (file_put_contents($filename,$output))
$message = "Your password has been changed to $pass";
else
$message = "There was an error creating your new password";
// send notification
mail($emailaddress,"Password Notification",$message,"From: Website <>");
?>
- - End Script Here - -







http://tips-scripts.com/password