Location: PHPKode > projects > DynPage > dynpage/logic/dynpage.request_pwd.inc.php
<?php
/*
DynPage V1.01 - A simple Content Management System
Copyright (C) 2009-2010 Matthias Wiede <hide@address.com>

This program is free software; you can redistribute it and/or modify 
it under the terms of the GNU General Public License as published by 
the Free Software Foundation; either version 3 of the License, or 
(at your option) any later version.

This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY 
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
for more details.

You should have received a copy of the GNU General Public License 
along with this program; if not, see http://www.gnu.org/licenses.
*/

require_once ("lib/input.inc.php");

$onLoad = "javascript:document.getElementById ('focus_id').focus();";

$FIELDS = array 
(
	"admin_email" => "0;e;m"
);

function generatePassword($length=9, $strength=0) {
	$vowels = 'aeuy';
	$consonants = 'bdghjmnpqrstvz';
	if ($strength & 1) {
		$consonants .= 'BDGHJLMNPQRSTVWXZ';
	}
	if ($strength & 2) {
		$vowels .= "AEUY";
	}
	if ($strength & 4) {
		$consonants .= '23456789';
	}
	if ($strength & 8) {
		$consonants .= '@#$%';
	}
 
	$password = '';
	$alt = time() % 2;
	for ($i = 0; $i < $length; $i++) {
		if ($alt == 1) {
			$password .= $consonants[(rand() % strlen($consonants))];
			$alt = 0;
		} else {
			$password .= $vowels[(rand() % strlen($vowels))];
			$alt = 1;
		}
	}
	return $password;
}


$values=array ();
$errors=array ();

$fShowErrors = false;
if ($cmd=="request_pwd")
	$fShowErrors = true;
$errCnt  = loadInputParams ($FIELDS, $values, 0, $errors, true, $fShowErrors);

$errText = "";
$successText = "";

switch ($cmd) 
{
	case "request_pwd":
		if ($errCnt>0)
			$errText = "Please check marked fields.";
		else
		if ($values["admin_email"]!=getConf ("admin_email"))
			$errText = "E-Mail Address unknown.";
		else
		{
			// Create random password
			srand ();
			$password = generatePassword (9,0xF);
			$emailText = "Your new password for DynPage is: ".$password."\n\n".
				"You can change your password under Config -> Change password.\n".
				"http://".$_SERVER['HTTP_HOST'].dirname ($_SERVER['REQUEST_URI'])."/?page=config_changepwd";
				
			$emailSubject = "New password for DynPage";
			if (mail (getConf ("admin_email"), utf8_decode($emailSubject), utf8_decode ($emailText), "From:".getConf ("admin_email"))) {
				$successText = "Your new password was sent to ".getConf ("admin_email").".";
				$hash = md5 ("admin:".$password);
				setConf ("login_hash", $hash);
			}
			else
				$errText = "Error while sending E-Mail.";
		}
		break;
}
?>
Return current item: DynPage