Jump to content

Help with this password generator?


BRADERY

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/204150-help-with-this-password-generator/
Share on other sites

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);

?>

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.