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
Share on other sites

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

Link to comment
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);

?>

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.