The code of an instance that uses ajax to verify the user name and password.

Source: Internet
Author: User

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.

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.