用PHP做过一个,你照着这个换成JS的就可以了:
下面为login.php:
session_start();
unset($_SESSION['name']);
mysql_connect("localhost", "root" ,"Changsha01") or die("Could not connect");
mysql_select_db("test") or die("Could not use db");
if (isset($_POST['submit'])) {
$name = trim($_POST['name']);
$password = trim($_POST['password']);
if (empty($name) || empty($password)) {
$flag = true;
}else {
$query = "SELECT password FROM users WHERE login_name = '" . $name . "'";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
if ($password == $row['password']) {
$_SESSION['name'] = $name;
header("location: index.php");
} else {
$flag = true;
}
}
}
?>
不难 但要花点时间