| 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;

?>

0 comments

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.