Minu VIKO : $_SESSION[firstname] $_SESSION[lastname]
|
|
Parooli muutmine
EOHTML;
}
function success_page()
{
return <<Parooli muutmine õnnestus. Palun sisene uue parooli abil.
Logi sisse
|
EOHTML;
}
function password_submiting_page()
{
return <<
NB! Paroolivahetuse järel peate uuesti sisse logima kasutades selleks uut parooli.
EOHTML;
}
require("viko_auth.php");
include("include/authenticate.php");
$PASSWORD_PATTERN = "^[a-zA-Z0-9]+$"; // TODO!
$PASSWORD_MIN_LENGTH = 4;
if(isset($_POST['submit']))
{
$errors = Array();
if ( !authenticate_student($_SESSION['username'], $_POST['old_password']) )
{
// Wrong old password
$errors[1]= "Vale parool. Parooli muutmiseks tuleb sisestada kehtiv parool.";
}
if ( $_POST['new_password'] != $_POST['new_password_repeat'] )
{
// Mismatching passwords
$errors[2]= "Paroolid, mis sa sisestasid ei ühti. Palun sisesta sama parool kaks korda.";
}
if ( !ereg($PASSWORD_PATTERN, $_POST['new_password']) )
{
// Password contains illegal characters
$errors[3]= "Parool sisaldab lubamatuid tähemärke";
}
if ( strlen($_POST['new_password']) < $PASSWORD_MIN_LENGTH )
{
// Password is too short
$errors[4]= "Parooli pikkuseks peab olema vähemalt 4 tähemärki";
}
if ( empty($errors) )
{
// If everything is correct, then change the password
save_password( $_SESSION['username'], $_POST['new_password'] );
// logout
session_start();
session_unset();
session_destroy();
// generate success page
include("include/header_student_main.php");
echo head_section();
echo( success_page() );
include("include/footer1.php");
}
else
{
// generate failure page
include("include/header_student_main.php");
echo head_section();
// List all error messages
echo( "" );
foreach ($errors as $error)
{
echo( "Viga: $error
\n" );
}
echo( "
\n" );
echo( password_submiting_page() );
include("include/footer1.php");
}
}
else
{
// generate initial page
include("include/header_student_main.php");
echo head_section();
echo( password_submiting_page() );
include("include/footer1.php");
}
?>