<?php
/*
 ########################################################################
#                                                                        #
#           Version 4       /                        /   /               #
#          -----------__---/__---__------__----__---/---/-               #
#           | /| /  /___) /   ) (_ `   /   ) /___) /   /                 #
#          _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___               #
#                       Free Content / Management System                 #
#                                   /                                    #
#                                                                        #
#                                                                        #
#   Copyright 2005-2006 by webspell.org                                  #
#                                                                        #
#   visit webSPELL.org, webspell.info to get webSPELL for free           #
#   - Script runs under the GNU GENERAL PUBLIC LICENSE                   #
#   - It's NOT allowed to remove this copyright-tag                      #
#   -- http://www.fsf.org/licensing/licenses/gpl.html                    #
#                                                                        #
#   Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at),   #
#   Far Development by Development Team - webspell.org                   #
#                                                                        #
#   visit webspell.org                                                   #
#                                                                        #
 ########################################################################
*/

eval ("\$title_lostpassword = \"".gettemplate("title_lostpassword")."\";");
echo $title_lostpassword;

if($_POST['submit']) {
  $email = $_POST['email'];
  $ergebnis = safe_query("SELECT * FROM ".PREFIX."user WHERE email = '$email' ");
	$anz = mysql_num_rows($ergebnis);
		
	if($anz) { 
	    $chars=array('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','1','2','3','4','5','6','7','8','9','0');
	    $max=count($chars);
	    $max--;
	    for($n=1; $n<7; $n++) {
	        $i = rand(0,$max);
		    $newpwd.=$chars[$i];
	    }
	    $newmd5pwd=md5($newpwd);
		
		$ds = mysql_fetch_array($ergebnis);
		safe_query("UPDATE ".PREFIX."user SET password='$newmd5pwd' WHERE userID='$ds[userID]' ");
		
	    $ToEmail = $ds[email];
		$ToName = $ds[username];
		$header = "Your Account for ".PAGETITLE;
		$Message = 'Your Account for '.PAGETITLE.'

!! Attention !! your password has been changed

your username: '.$ds[username].'
your new password: '.$newpwd.'

have fun on our page
'.$hp_url;
		
		if(mail($ToEmail,$header, $Message, "From:".$admin_email."\r\nX-Mailer: PHP/" . phpversion()))	echo'Your account has been found<br><br>
		     You will get an e-mail to <b>'.$ds[email].'</b> with your account in seconds.<br><br>
			 &#8226; <a href="index.php?site=login">login</a>';
			 
			else echo 'There was a problem while sending mail. Please contact the webmaster.';
			 
	
	}
	else {
	    echo'no user found!';
	}
	 
}
else {
    echo'<form method="post" action="index.php?site=lostpassword">
		 Your E-Mail: <input type="text" name="email" size="25" class="form_off" onFocus="this.className=\'form_on\'" onBlur="this.className=\'form_off\'"> <input type="submit" name="submit" value="get password">
		 </form>';
}


?>
