Analyze the existing password from database without refresh using ajax concept. The given password is compared with existing password in database and display whether it is correct or not. Here Ajax is used to analyze or check the exisiting password with The HTML, Ajax,Mysql coding are provided below.You can try if you need to check existing password and change password using Ajax.
Table structure for table `change_password`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
CREATE TABLE IF NOT EXISTS `change_password` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`confirm_password` varchar(50) NOT NULL,
PRIMARY KEY (`id`)
)
INSERT INTO `change_password` (`id`, `username`, `password`, `confirm_password`) VALUES
(1, 'ramkumar', '123', '123');
Change_password.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
<?php
include("conn.php");
if(isset($_POST['submit']))
{
$password=$_POST['password'];
$confirmpasssword=$_POST['confirmpassword'];
if($password==$confirmpasssword)
{
$insert=("update change_password set password='$confirmpasssword', confirm_password='$confirmpasssword' where username='ramkumar'");
$insert1=mysql_query($insert);
echo "<script> alert('Your password is changed');</script>";
}
else
{
echo "<script> alert(Your password is changed);</script>";
}
}
?>
<html>
<head>
<title>Change Password</title>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","check_password.php?q="+str,true);
xmlhttp.send();
}
</script>
<script type="text/javascript">
function pass()
{
var pwd=document.getElementById("password").value;
var cpwd=document.getElementById("confirmpassword").value;
if(pwd==cpwd)
{
var t1=document.getElementById('pass').innerHTML="Password Match";
/*t1.style.display='block';*/
}
else
{
var t1=document.getElementById('pass').innerHTML="Password does not Match";
/* t1.style.display='block';*/
document.form.password.focus();
}
}
</script>
<style type="text/css">
body
{
}
.table
{
color:#000000;
}
.st
{
color:#FF0000;
}
</style>
</head>
<form id="form" name="form" method="post" action="" onSubmit="return passvali();">
<table width="50%" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="#C1C1FF">
<tr>
<td colspan="2" align="center"> <h2>Change Password</h2></td>
</tr>
<tr>
<th> Current Password <span style="color:#F00;">*</span></th>
<td><input type="password" name="cur_pwd" class="input"id="oldpassword"placeholder="Enter Current Password" onChange="showUser(this.value)" /></td>
<td> <span class="st" id="txtHint"></span> </td>
</tr>
<tr>
<th>New Password <span style="color:#F00;">*</span></th>
<td><input type="password" name="password" class="input" id="password" placeholder="Enter your Password"/></td>
</tr>
<tr>
<th> Confirm Password <span style="color:#F00;">*</span></th>
<td><input type="password" name="confirmpassword" class="input" id="confirmpassword" placeholder="Enter Confirm Password" onChange="return pass()" /></td>
<td><span id="pass" style="color:#F00;"> </span> </td>
</tr>
<tr>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Submit" style="width:80px;" /></td>
</tr>
</table>
</form>
</body>
</html>
check_password.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
<?php
include('conn.php');
$password=$_GET['q'];
$select=mysql_query("select * from change_password where username='ramkumar'");
$fetch=mysql_fetch_array($select);
$data_pwd=$fetch['password'];
if($data_pwd==$password)
{
echo "Password match";
}
else
{
echo "provide valid password";
}
?>
Form Design
Password Checking from database using Ajax:
Password Matching:





[...] Check Existing Password in Database using Ajax [...]