<?

session_start();

// wenn delete gesetzt ist, sollen die bereits berechnteten Passwoerter geloescht werden
if (!empty ($HTTP_GET_VARS['delete']))
{
        // den Ergebnisstring zuruecksetzen
        $_SESSION['passwd'] = null;
}

if (!empty ($HTTP_POST_VARS['user']) && !empty($HTTP_POST_VARS['password']))
{
        // erstmal den Salt berechnen
        srand ((double)microtime()*1000000);        
        $s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890./";
        $s1= $s{rand(0, strlen ($s)-1)};
        $s2= $s{rand(0, strlen ($s)-1)};
        $salt = $s1 . $s2;
        
        if (empty ($HTTP_POST_VARS['sysuser']))
        {
                $_SESSION['passwd'] .= $HTTP_POST_VARS['user'] . ":" . crypt ($HTTP_POST_VARS['password'], $salt) . "\n";
        }
        else
        {
                $_SESSION['passwd'] .= $HTTP_POST_VARS['user'] . ":" . crypt ($HTTP_POST_VARS['password'], $salt) . ":" . $HTTP_POST_VARS['sysuser'] . "\n";
        }
}
?>

<html>
        <form action="index.php" method="post">
                <table>
                        <tr><td>CVS-Benutzername:</td><td><input name="user" type="text" /></td></tr>
                        <tr>
                                <td>CVS-Passwort:</td>
                                <td><input name="password" type="password" /></td>
                        </tr>
                        <tr>
                                <td>System-Benutzername: </td>
                                <td><input name="sysuser" type="text" /></td>
                        </tr>
                        <tr>
                                <td colspan="2"><input type="submit" value="Hinzufuegen!" /></td>
                        </tr>
                </table>
        </form>
        <p>Einhalt der Datei <b>passwd</b>:</p>
        <pre>
        <?
                echo "\n";
                echo $_SESSION['passwd'];
        ?>
        </pre>        
        Inhalt <a href="index.php?delete=true">loeschen</a><br />
</html>