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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.