college-cwk-spelling-test/login.php

34 lines
864 B
PHP
Raw Normal View History

2014-03-04 05:08:11 -08:00
<?php
require "common/common.php";
2014-04-09 08:56:22 -07:00
// Check for submissions
2014-03-04 05:08:11 -08:00
if ($_POST['submitted']=="true"){
2014-04-09 08:56:22 -07:00
// Check username and password
2014-03-04 05:08:11 -08:00
$user = User::getUsername($_POST['username']);
if ($user){
2014-04-09 08:56:22 -07:00
// hash password to be checked against database
2014-03-04 05:08:11 -08:00
$hash = md5($_POST['password']);
if ($hash == $user->password){
2014-04-09 08:56:22 -07:00
// Log user in
2014-03-04 05:08:11 -08:00
$_SESSION['user'] = $user->username;
header("location: index.php");
}
}
}
2014-04-09 08:56:22 -07:00
// Show page
2014-03-04 05:08:11 -08:00
showHeader("Log in");
?>
<form action="login.php" method="post">
<input type="hidden" name="submitted" value="true" />
<?php
if ($_POST['submitted']=="true"){
2014-04-09 08:56:22 -07:00
// Show wrong username / password message
2014-03-04 05:08:11 -08:00
echo "<span style=\"color:red;\">Wrong username / password</span><br>";
}
?>
Username: <input type="test" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Log in">
</form>