Ajax and JavaScript Authenticate user login to __ database

Source: Internet
Author: User

Ajax and JavaScript Authentication User Login

index.html

<!
DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >  

Login.js

var btn = document.getElementById (' btn ');
var re = document.getElementById (' re ');
var user = document.getElementById (' user ');
var password = document.getElementById (' password ');
	Btn.onclick = function () {var isvalidate=false;
		if (!user.value.match (/^\s{2,20}$/)) {user.classname = ' userred ';
		User.focus ();
	Return
		else {user.classname = ' text ';
	Isvalidate=true;
		} if (Password.value.length<3 | | password.value.length>20) {password.classname = ' userred ';
		Password.focus ();
	Return
		else {password.classname = ' text ';
	Isvalidate=true;
		} if (isvalidate) {var ajax = Ajax (); Ajax.get (' login.php?user= ' +document.getelementbyid (' user '). value+ ' &password= ' +document.getelementbyid ('
			Password '). value, function (data) {var con = document.getElementById (' con ');
			eval (data);
				if (login) {con.innerhtml = ' <font color= ' green ' > Login succeeded, jump in ...</font> '; Location = ' xx.php '; Specify jump page after successful login} else {con.innerhtml = ' <font color= ' reD "> account or password error.
			</font> ';
	}
		});
	} Re.onclick = function () {user.value= "";
Password.value= ""; }

login.php

<?php
require_once './config.inc.php ';
$m = new Model ();
$user = $_get[' user '];
$password = $_get[' password '];
$count = $m->total (' users ', ' user= '. $user. "' and password= '. SHA1 ($password).
if ($count) {
	setcookie (' user ', $user);
	echo "var login=true";
} else {
	echo "var login=false";
}
? >

Effect Display chart:



ajax.js files in the previous article can be found in the database structure of two fields (User,password) can be.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.