The example of this article introduced the AJAX authentication username and password of the specific code for your reference, the specific contents are as follows
1.ajax Body part
var xmlrequest; function Createxmlhttprequest () {if (window).
XMLHttpRequest) {xmlrequest=new XMLHttpRequest (); else if (window.
ActiveXObject) {try{xmlrequest=new ActiveXObject ("msxm12.xmlhttp");
catch (e) {try{xmlrequest=new ActiveXObject ("Microsoft.XMLHTTP");
The catch (e) {}}} function login () {createxmlhttprequest ();
var user = document.getElementById ("YHM"). Value;
var password = document.getElementById ("MM"). Value; if (user== "" | |
password== "") {alert ("Please enter username and password!");
return false;
The var url = "check.php?user=" +user+ "&password=" +password;
Xmlrequest.open ("POST", url,true);
Xmlrequest.setrequestheader ("Content-type", "application/x-www-form-urlencoded"); Xmlrequest.onreadystatechange = function () {if (xmlrequest.readystate = 4) {if (xmlrequest.status==200) {var msg
= Xmlrequest.responsetext; if (msg== ' 1 '){alert (' username or password is wrong! ');
User= "";
Password= "";
return false;
} else{window.location.href= "index1.html";
}}} xmlrequest.send ("user=" +user+ "&password=" +password); }
2.html Code
<input placeholder= "username" autofocus= "type=" text "name=" username "> <input placeholder=
" password "type=" Password "name=" password ">
<button id=" DL "onclick=" Login () "> Login </button>
3. Here is the use of SHA1 encryption, your password and database name changes to your own can
<?php
$yhm 1=$_post[' user '];
$mm 1=$_post[' password '];
@ $DP =new mysqli (' localhost ', ' root ', ' Your password ', ' your database name ');
$yhm 2=sha1 ($yhm 1);
$MM 2=SHA1 ($mm 1);
$query = "SELECT * from Zhuce where yhm= ' $yhm 2 ' and mm= ' $mm 2 '";
$result = $DP->query ($query);
$num = $result->num_rows;
if (! $num) {
echo "1";
}
$DP->close ();
? >
The above is the entire content of this article, I hope to help you learn.