The code of an instance that uses ajax to verify the user name and password.
This article introduces the code for verifying the username and password of ajax for your reference. The details are as follows:
1. ajax subject
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 ");} catch (e) {}}} function login () {createXMLHttpRequest (); var user = document. getElementById ("yhm "). value; var password = document. getElem EntById ("mm"). value; if (user = "" | password = "") {alert ("Enter your username and password! "); Return false;} 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 ('user name or Password error! '); 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 () "> logon </button>
3. Here we use sha1 encryption to change your password and database name to your own.
<? Php $ yhm1 =$ _ POST ['user']; $ mm1 =1 _ POST ['Password']; @ $ dp = new mysqli ('localhost', 'root ', 'Your password', 'Your database name'); $ yhm2 = sha1 ($ yhm1); $ mm2 = sha1 ($ mm1 ); $ query = "select * from zhuce where yhm = '$ yhm2' and mm = '$ mm2'"; $ result = $ dp-> query ($ query ); $ num = $ result-> num_rows; if (! $ Num) {echo "1" ;}$ dp-> close ();?>
The above is all the content of this article, hoping to help you learn.