Here’s the code from the weblogin.common.inc.php file for generating a password, and for sending the login details to somebody:
function webLoginGeneratePassword($length = 10) {
$allowable_characters = "abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
$ps_len = strlen($allowable_characters);
mt_srand((double)microtime()*1000000);
$pass = "";
for($i = 0; $i < $length; $i++) {
$pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
}
return $pass;
}
// Send new password to the user
function webLoginSendNewPassword($email,$uid,$pwd,$ufn){
global $modx, $site_url;
$mailto = $modx->config['mailto'];
$websignupemail_message = $modx->config['websignupemail_message'];
$emailsubject = $modx->config['emailsubject'];
$emailsender = $modx->config['emailsender'];
$site_name = $modx->config['site_name'];
$site_start = $modx->config['site_start'];
$message = sprintf($websignupemail_message, $uid, $pwd); // use old method
// replace placeholders
$message = str_replace("[+uid+]",$uid,$message);
$message = str_replace("[+pwd+]",$pwd,$message);
$message = str_replace("[+ufn+]",$ufn,$message);
$message = str_replace("[+sname+]",$site_name,$message);
$message = str_replace("[+semail+]",$emailsender,$message);
$message = str_replace("[+surl+]",$site_url,$message);
if (!ini_get('safe_mode')) $sent = mail($email, $emailsubject, $message, "From: ".$emailsender."\r\n"."X-Mailer: Content Manager - PHP/".phpversion(), "-f {$emailsender}");
else $sent = mail($email, $emailsubject, $message, "From: ".$emailsender."\r\n"."X-Mailer: Content Manager - PHP/".phpversion());
if (!$sent) webLoginAlert("Error while sending mail to $mailto",1);
return true;
}
It should not be difficult to adapt this to a stand-alone script; or even to a module. Or, you could simply use the email address or name as the password, using the md5() function to make the hash to insert into the database. Sending the email is rather obvious, just collect the variables, build the message, and send the mail, using the phpmailer class to send via SMTP if your host doesn’t allow the PHP mail() function.