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
https://forums.phpfreaks.com/topic/41856-random-password-generator/
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.

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

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.