BRADERY Posted June 8, 2010 Share Posted June 8, 2010 <?php echo "BRADERY OWNS\n\nBegin loading script...\n"; /////////////////////////////////////////////////// //////////////PASSWORD GEN 1.0///////////////////// /////////////////////////////////////////////////// //////////////PASSWORD LENGTH////////////////////// /////////////////////////////////////////////////// $password_length =24; /////////////////////////////////////////////////// ////////////CHARACTERS FOR PASSWORD//////////////// /////////////////////////////////////////////////// $characters='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789$*%><)(]['; /////////////////////////////////////////////////// //////////////HOW MANY PASSWORDS/////////////////// /////////////////////////////////////////////////// $password_count = 20; /////////////////////////////////////////////////// /////////PASSWORDS SAVED TO C:///////////////////// /////////////////////////////////////////////////// $filepath = '/passwords.txt'; /////////////////////////////////////////////////// //////////DO NOT EDIT BELOW THIS LINE////////////// /////////////////////////////////////////////////// $passwords = ""; for($c = 0; $c < $password_count; $c++){ for($i = 0; $i < $password_length; $i ++) { $passwords .= $characters[rand(0, strlen($characters)-1)]; } $passwords .= PHP_EOL; } if(file_put_contents($filepath, $passwords) !== false) echo "Passwords generated and saved to $filepath"; else echo "Error Writing to file $filepath"; sleep(1000000); ?> If possible, can someone tell me how to make it to where the first 2 characters of the password generated is only numbers? No symbols or letters? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/204150-help-with-this-password-generator/ Share on other sites More sharing options...
dabaR Posted June 8, 2010 Share Posted June 8, 2010 There are many ways, here's one: $password = rand(0,9) . rand(0,9) . $password_22_chars_long; Quote Link to comment https://forums.phpfreaks.com/topic/204150-help-with-this-password-generator/#findComment-1069252 Share on other sites More sharing options...
BRADERY Posted June 8, 2010 Author Share Posted June 8, 2010 oops, I meant to say only letters for the first 2 characters of the password.. no numbers or symbols also I put that in and it only writes a 2 digit number to my text file Quote Link to comment https://forums.phpfreaks.com/topic/204150-help-with-this-password-generator/#findComment-1069258 Share on other sites More sharing options...
jcbones Posted June 8, 2010 Share Posted June 8, 2010 This is one way, regex might not be right, un-tested. if(!preg_match('~^[A-Za-z]{2}~',$password)) { $hold = $characters[rand(0,51)]; $hold .= $characters[rand(0,51)]; $password = preg_replace('~^(.){2}~',$hold,$password); } Quote Link to comment https://forums.phpfreaks.com/topic/204150-help-with-this-password-generator/#findComment-1069264 Share on other sites More sharing options...
Psycho Posted June 8, 2010 Share Posted June 8, 2010 This will generate the passwords into an array for you as you specify. Use implode() to convert to a string to write into the file: <?php function generatePasswords($count, $length) { $passwordAry = array(); $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789$*%><)(]['; for($i=0; $i<$count; $i++) { $passwordAry[$i] = $characters[rand(0, 51)] . $characters[rand(0, 51)]; $passwordAry[$i] .= substr(str_shuffle($characters), 0, $length-2); } return $passwordAry; } $passwords = generatePasswords($password_count, $password_length); ?> Quote Link to comment https://forums.phpfreaks.com/topic/204150-help-with-this-password-generator/#findComment-1069284 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.