<?php // lost password v0.1
/*    so, why the fuck does this bloody think NOT WANT TO work?
    drop a line in NAO, thanks in advance: http://www.netalive.org/topics/43132

    I've hacked this script in Quanta Plus, thus I'm able to properly check out if any brackets are not closed.
    Probably it's just some stupid mistake, like a missing semi-colon (';') or dot ('.').

    about the functions:
    - get_random_pwd() obviously generates a new passwort. this one DOES work properly. It's been used within the registration script and there's NO error at all.
    - clean_mysql_var() cleans any stuff that comes from outside (ie. $_POST- or $_REQUEST-variables) and prepares it for being used in an SQL-query
    - clean_form_var() does nearly the same as the function above, but excludes the SQL-preperation stuff
*/

?>
<div id="page-wrap">
    <div id="main">
        <h2><? echo $_page_title?></h2>
<?    switch(empty($_POST['pw_lost_login'])) {
        case 
false// generate new password, save it to the db and send it to the user, too
            // check if username exists at all
            
$check mysql_query(
                                
'SELECT user_id, user_login, user_email FROM saf_userbase WHERE user_login = '
                                
clean_mysql_var($_POST['pw_lost_login'])
                                . 
' LIMIT 1'
                                
$link
                                
);
            
$check_row mysql_fetch_array($check);
            if(
$check != false && mysql_num_rows($check) > 0) {
                
$new_pw get_random_pwd(7);

                
$update mysql_query    (
                                        
"UPDATE saf_userbase SET user_pw = '".md5($new_pw)."' WHERE user_id = ".$check_row['user_id'].' LIMIT 1'
                                        
$link
                                        
);
                if(
$update != false) {
                    
$msg =     "Willkommen zurueck bei SaF!\n"
                            
."Sie haben ein neues Passwort angefordert.\n\n"
                            
."Neues Passwort: ".md5($new_pw)."\n\n"
                            
."In Ihrem Profileinstellungen koennen Sie es aendern.\n\n"
                            
."Noch viel Erfolg mit Ihrem Account bei SaF,\n\n"
                            
."das SaF-Team.";

                    
$mail_sent mail    (
                                        
$check_row['user_email']
                                        , 
'Search and Find: Neues Passwort'
                                        
$msg
                                        
"From: bounce@somedomain.de\nX-Mailer: saf-password-recovery/0.1"
                                        
);

                    if(
$mail_sent != true) { // I commented this one out, but the error mesage returns, anyway. :-/
                        
exit('<p>Aus unbekanntem Grund konnte die Mail mit Ihrem neuen Passwort nicht versendet werden. Bitte verst&auml;ndigen Sie den Webmaster!</p>')
                    }
?>
        <p>Ihr neues Passwort wurde Ihnen soeben zugesandt.</p>

        <p><a href="index.php">Zur&uuml;ck zur Startseite</a></p>
<?                } else { // i've commented this out, too. - but it SHOULD work, nonetheless!
                    
exit('<p>Datenbank-Fehler aufgetreten. MySQL-Datenbank meldet zur&uuml;ck:'.mysql_error().'<br />Bitte verst&auml;ndigen Sie den Webmaster!</p>')
                }
            } else { 
?>
        <p>Der Benutzername <strong><? echo clean_form_var($_POST['pw_lost_login']); ?></strong> konnte leider nicht gefunden werden. Versichern Sie sich, dass Sie ihn richtig eingegeben haben und versuchen Sie es dann nochmals:</p>

        <form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
            <p><span>Benutzer-Login:</span>
            <input type="text" name="pw_lost_login" size="30" style="width: 200px" value="<? echo clean_form_var($_POST['pw_lost_login']); ?>" /></p>

            <p><button type="submit">Neues Passwort anfordern</button></p>
        </form>
<?            }
        break;
        default: 
?>
        <p>Sie k&ouml;nnen sich nicht mehr an Ihr Passwort erinnern? Macht nichts. Geben Sie folgend bitte Ihren Benutzernamen ein, dann senden wir Ihnen automatisch ein neues an die in Ihrem Benutzeraccount angegebene E-Mail-Adresse:</p>

        <form method="post" action="<? echo $_SERVER['PHP_SELF']; ?>">
            <p><span>Benutzer-Login:</span>
            <input type="text" name="pw_lost_login" size="30" style="width: 200px" /></p>

            <p><button type="submit">Neues Passwort anfordern</button></p>
        </form>
<?        break;
    } 
?>
    </div>
</div>