Random Password Generator [PHP]

  • Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

ZionHD

Leader
Retired Staff
Nov 8, 2014
184
215
53
This is a PHP Version of a Random Password Generator. This will generate random passwords for you. You can change the length, to allow special chars, caps, no caps, and numbers. This has more chars for it to choose from which I forgot to add to the C++ version of it, but oh well.

Code:
<?php
/*
* General purpose of this program is to generate a password for you.
* PHP Version
* Created by ZionHD
* Copyright (c) 2015 Console-Forums
*/

function genChar($numbers, $specials, $caps, $chars) // This will randomly select a character from array
{
    $number = array ( "0", "1", "2", "3", "4", "5", "6", "7", "8", "9");
    $special = array( "!", "@", "#", "$", "%", "^", "&", "*", "\"", ">", "<", "(", ")", "-", "_",  "+", "=", "{", "}", "[", "]", "\\", "|", ":", ";", "'", ",", ".", "?", "/", "~", "`");
    $capsChar = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");
    $char = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z");
   
    // If any of the variables are false it will  add it to an
    // array
    if (!$numbers) $ignore[] = 0;
    if (!$specials) $ignore[] = 1;
    if (!$caps) $ignore[] = 2;
    if (!$chars) $ignore[] = 3;
   
    $ch = NULL; // Character to return
   
    // Keep trying to select a char, capChar, special, or number until one which has not been ignored this will stop.
    while (1)
    {
        $type = rand(0, 3); // Randomly select 0 - 3
       
        if (!in_array($type, $ignore))
        {
            if ($type == 0)
            {
                $len = count($number) - 1;
                $ran = rand(0, $len);
                $ch = $number[$ran];
                break;
            }
            else if ($type == 1)
            {
                $len = count($special) - 1;
                $ran = rand(0, $len);
                $ch = $special[$ran];
                break;
            }
            else if ($type == 2)
            {
                $len = count($capsChar) - 1;
                $ran = rand(0, $len);
                $ch = $capsChar[$ran];
                break;
            }
            else if ($type == 3)
            {
                $len = count($char) - 1;
                $ran = rand(0, $len);
                $ch = $char[$ran];
                break;
            }
        }
    }
   
    return $ch;
}

$allowNumbers = TRUE;
$allowSpecials = TRUE;
$allowCaps = TRUE;
$allowChars = TRUE;

$passLength = 15; // I recommend having a 15+ character password since it is harder to guess

$inc = 0;

$pass = "";

while ($inc != $passLength)
{
    $ch = genChar($allowNumbers, $allowSpecials, $allowCaps, $allowChars);
    if ($ch !== NULL)
    {
        $pass .= "{$ch}";
        $inc++;
    }
}

$pass = htmlspecialchars($pass); // Sanitize before displaying

printf("Password Generated: <br />%s", $pass);
?>
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Chat Bot:
    LilBoat100 has left the room.
  • Chat Bot:
    keonhacaivoto is our newest member. Welcome!
  • Chat Bot:
    QM|T has joined the room.
  • Chat Bot:
    estro101 is our newest member. Welcome!
  • Chat Bot:
    yeclipsex is our newest member. Welcome!
  • Chat Bot:
    QM|T has joined the room.
  • Chat Bot:
    Diabloron is our newest member. Welcome!
  • Chat Bot:
    mr kiki is our newest member. Welcome!
  • Chat Bot:
    NorwayVon is our newest member. Welcome!
  • Chat Bot:
    QM|T has joined the room.
  • Chat Bot:
    cynthia is our newest member. Welcome!
  • Chat Bot:
    LilBoat100 has joined the room.
  • @ LilBoat100:
    been a min
  • @ LilBoat100:
    i have uncharted 3, (digital) my disc aint working for shit lol, so whenever i try finding "LAN Party" its not on digital, only on disc. so if theres like a eboot maybe, or something i can do to activate the LAN Party to play offline, that shit would be dope bro. anyone.
  • @ LilBoat100:
    or maybe if i download it as iso? idk
  • Chat Bot:
    tazl is our newest member. Welcome!
  • Chat Bot:
    LilBoat100 has joined the room.
  • Chat Bot:
    QM|T has joined the room.
  • Chat Bot:
    salih01barwari has left the room.
  • Chat Bot:
    ImMike is our newest member. Welcome!
  • Chat Bot:
    ImMike has posted a new reply in the thread "PS4 v3.50 Neighborhood".
  • Chat Bot:
    QM|T has joined the room.
  • Chat Bot:
    nhandinhkeonhacaidee is our newest member. Welcome!
  • Chat Bot:
    go88ttacom is our newest member. Welcome!
      Chat Bot: go88ttacom is our newest member. Welcome!