digitalgod Posted March 8, 2007 Share Posted March 8, 2007 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 More sharing options...
linuxdream Posted March 8, 2007 Share Posted March 8, 2007 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 https://forums.phpfreaks.com/topic/41856-random-password-generator/#findComment-202968 Share on other sites More sharing options...
digitalgod Posted March 8, 2007 Author Share Posted March 8, 2007 that's what I thought, thanks linuxdream, I'll try to google for some AJAX examples. Link to comment https://forums.phpfreaks.com/topic/41856-random-password-generator/#findComment-202975 Share on other sites More sharing options...
brooksh Posted March 8, 2007 Share Posted March 8, 2007 <?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 https://forums.phpfreaks.com/topic/41856-random-password-generator/#findComment-202983 Share on other sites More sharing options...
digitalgod Posted March 12, 2007 Author Share Posted March 12, 2007 thanks brooksh but like I said I already made my own password generator, just trying to get it to generate everytime a button is clicked Link to comment https://forums.phpfreaks.com/topic/41856-random-password-generator/#findComment-205520 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.