Jump to content

Generating a random password without refreshing the page.


coupe-r

Recommended Posts

Here is my code

 

if(isset($_POST['pass_btn']))
{
    $numchars = 8;
    $chars = explode(',','2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z,2,3,4,5,6,7,8,9');
    $password='';
        for($i=0; $i<$numchars;$i++)
        {
            $password.=$chars[rand(0,count($chars)-1)];
        }
}

 

This is set up so when a person pressing the pass_btn, a password is provided.  This works just fine.  However, it refreshes the page and clears all other data that user may have entered.

 

Suggestions?

  Quote

Here is my code

 

if(isset($_POST['pass_btn']))
{
    $numchars = 8;
    $chars = explode(',','2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,i,j,k,m,n,p,q,r,s,t,u,v,w,x,y,z,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z,2,3,4,5,6,7,8,9');
    $password='';
        for($i=0; $i<$numchars;$i++)
        {
            $password.=$chars[rand(0,count($chars)-1)];
        }
}

 

This is set up so when a person pressing the pass_btn, a password is provided.  This works just fine.  However, it refreshes the page and clears all other data that user may have entered.

 

Suggestions?

 

Without refreshing you need either javascript or call another script by using ajax which is infact javascript too

I think with javascript with innerHTML you can do this. let me give you a small example in a bit.

-edit: you could of course also assign session or post variables to preserve the data

 

here is an input  field that generates a random number on mouseover. ::)

<input id="pass" type="text" name="pass" onmouseover="document.getElementById('pass').value = Math.random();" value="lalala"></input>

maybe you can use it

Well, the password generate button is the last part of the form and if they fill out they form and then press the generate button, all there stuff is gone.  Thats the main concern.

 

AJAX may be cool too :)  Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.