Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts
| 0 comments ]

main.php

<html>
<head><TITLE>Check User Name</TITLE>
<script language="JavaScript" src="jsFile.js" type="text/javascript"></script>
</head>
<body>
<table align="center" border="0">

<TR>
<TD><h3>Check User Name</h3></TD>
</TR>

<TR>
<TD height="10">&nbsp;</TD>
</TR>
<TR>
<TD>Username</TD>
<TD>
<input type="text" name="txtName" id="txtName">
</TD>
</TR>
<TR>
<TD>Password</TD>
<TD>
<input type="text" name="txtpass" id="txtpass">
</TD>
</TR>

<TR><TD colspan='2' align='center'> <span id='resSpan'>&nbsp;</span></TD></TR>

<TR><TD colspan='2' align='center'> <input type='button' value='Check User' onclick='chkLogin()'></TD></TR>
</table>
</body>
</html>


jsFile.js

function chkLogin()
{


var nameVal=$("#txtName").val();
var pwd==$("#txtpwd").val();
var url=checkLogin.php';
var data='name='+nameVal+'&pwd='+pwd;
$.ajax({
type: "POST",
url: url
data: data,
success: function(msg){
document.getElementById('resSpan').innerHTML=msg;
}
});


}


checkLogin.php

<?php

// Db connection edit with your db connection parameters

$conn=mysql_connect("localhost","root","root");
$db=mysql_select_db("dbUserlogs");


$username'=trim($_POST['name']);
$pwd=$_POST['pwd'];

if(!empty($username)){

$sqlqry="SELECT * FROM user_entity where user_name='$username'";
$res=mysql_query($sqlqry) or die(mysql_error());

$count=mysql_num_rows($res);

if($count==0){

$msg='The user '+$username +'does not exist';
}else{

$sqlqry="SELECT * FROM user_entity where user_name='$username' and password='$pwd'";
$res=mysql_query($sqlqry) or die(mysql_error());

$count=mysql_num_rows($res);
if($count==0){
$msg="Incorrect Password!";
}else{


$msg="valid login!";

}

}else{

$msg='Enter username';
}
echo $msg;

?>


| 0 comments ]

The following example will generate random password  for the user name .

main.php

<?php 
$template=<<<T1
<html>
<head><title>Random Passwod Generator </title>
<script language="JavaScript" src="getRandom.js" type="text/javascript"></script>
</head>
<body>
<table align="center"><tr>
                <td colspan='2' align='center'><b>Generate Random Password</b></td>
        </tr>
        <tr>
                <td>User name</td>
                <td>
                        <input type="text" name="txtName" id="txtName">
                        &nbsp;&nbsp;<input type="button" onclick="getRandompwd()" value="Get Password">
                </td>
        </tr>
</table>
</body>
</html>
T1;

echo $template;

?>


getRandom.js

function getRandompwd()
{

var nameVal=$("#txtName").val();
var url='randomPwd.php';
var data='name='+nameVal;
 $.ajax({
   type: "POST",
   url: url
   data: data,
   success: function(msg){
 var respArray = msg.split('+');
if(respArray [0]=="randompwd"){
$("#txtName").val=respArray[1];
 
   }
 });
}


randomPwd.php

<?php

$name=$_REQUEST['name];
$charsArray=array();
$randPwd='';
$pwdLen=10;
$maxLen=25;
$expLen=0;

$chars = "a,b,c,d,e,f,g,h,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,F,G,H,J,K,L,M,N,P,Q,R,S,T,V,W,X,Y,Z,,@,#,%,&,*,$,1,2,3,4,5,6,7,8,9"; 
$charsArray = explode(",", $chars );

  while($expLen < $maxLen){
           $rands =  rand(0,5);
           $rand_keys .= array_rand($charsArray , $rands);
          $expLen=strlen($rand_keys);
             
        }
      

       $rands=rand(0,9),
       $randPwd= substr($rand_keys,$rands,pwdLen);
        echo 'randompwd'.'+'.$randPwd;

?>