Jump to content

random password generator


digitalgod

Recommended Posts

Hey guys,

 

not sure if this is in the right forum or not but I was wondering how can I make a password generator using php and javacript so that whenever a button is clicked it generates a random password in a text box.

 

I've already done the password generator code. When I click on the button it generates a password but if I click it again it won't generate a different code.

So is there a way to have it generate a different password each time? Right now when I click on the button it will call the javascript function to change the text in the input box to  echo rand_pass(); like so

 

<input id="password" name="password" type="text" size="71" maxlength="128" style="margin-top:2px;" tabindex="26"/> 
<input name="rand_pass" id="rand_pass" type="button" value="generate" onClick="generate( 'password', '<?php echo rand_pass(); ?>'  );" class="Buttons">

Link to comment
Share on other sites

PHP only processes on the server side so you can't expect it to process through javascript unless you submit the form again or use AJAX. Your rand_pass() must be javascript to be used in this case...or else it only gets used once (as is the problem you are experiencing). Otherwise, you will have to submit the form and reload the page...or use AJAX.

Link to comment
Share on other sites

<?php/** * The letter l (lowercase L) and the number 1 * have been removed, as they can be mistaken * for each other. */function createRandomPassword() {    $chars = "abcdefghijkmnopqrstuvwxyz023456789";    srand((double)microtime()*1000000);    $i = 0;    $pass = '' ;    while ($i <= 7) {        $num = rand() % 33;        $tmp = substr($chars, $num, 1);        $pass = $pass . $tmp;        $i++;    }    return $pass;}// Usage$password = createRandomPassword();echo "Your random password is: $password";?> 

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.