Advertise Here

Author Topic: PHP Random Pass Generator Script  (Read 17163 times)

0 Members and 1 Guest are viewing this topic.

Offline Colette Brunel

  • SMF For Free Sr. Member
  • *
  • Posts: 424
    • View Profile

  • Total Badges: 17
    Badges: (View All)
    Poll Voter Level 4 Fourth year Anniversary Windows User Topic Starter
PHP Random Pass Generator Script
« on: January 09, 2009, 10:35:03 pm »
I've enhanced my script a bit and included the "form" that you all are asking for. I also added a built-in error handling system and options to use numbers, upper case letters, lower case letters, and symbols.

Code: [Select]
<?php
// Password Generator v1.2
// Created by ccbtimewiz (ccbtimewiz@jeunosky.net)

$limit 100;
function 
generate_pass()
 {
global $limit;

$pass '';
$length '';
$nums = array();
$caps = array();
$lowers = array();
$symbols = array();

if ($_REQUEST['usenums'])
$nums range('0''9');

if ($_REQUEST['usecaps'])
$caps range('A''Z');

if ($_REQUEST['uselower'])
$lowers range('a''z');

if ($_REQUEST['usesymbols'])
$symbols =  array_merge(range("{""~"), range(":""@"));

$chars = array();

if (!empty($nums) )
 {
foreach ($nums as $value)
$chars[] = $value;
 }

if (!empty($caps) )
 {
foreach ($caps as $value)
$chars[] = $value;
 }

if (!empty($lowers) )
 {
foreach ($lowers as $value)
$chars[] = $value;
 }

if (!empty($symbols) )
 {
foreach ($symbols as $value)
$chars[] = $value;
 }

if (empty($chars))
$chars array_merge(array_merge(range('a''z'), range('A''Z')), range('0''9'));

$count count($chars);

if( is_numeric($_REQUEST['value']) && (abs($_REQUEST['value']) < $limit) && (!empty($_REQUEST['value'])) )
$length abs((int) $_REQUEST['value']);
elseif (empty($_REQUEST['value']) && ($_REQUEST['value'] != '0') && !isset($_REQUEST['value']))
$length 'keepalive';
else
show_error();

mt_srand((double)microtime() * 1000000);

if ($length != 'keepalive')
 {
for($i 0$i $length$i++)
$pass .= $chars[mt_rand(0$count 1)];
 }

if (!empty($pass))
echo "Your password is:<br /><tt><strong>$pass</strong></tt>";
 }

function 
show_error()
 {
global $limit;

if ($limit <= abs($_REQUEST['value']))
$error "
<strong>The following errors were processed during your request:</strong>
<br />
<em>&bull; Length input is over or equal to 
$limit characters.</em>";
elseif( !is_numeric($_REQUEST['value']) && (!in_array($_REQUEST['value'], array('''0''keepalive'))) )
$error "
<strong>The following errors were processed during your request:</strong>
<br />
<em>&bull; Length input contained non-numerical characters.</em>"
;
elseif ($_REQUEST['value'] == '0')
$error "
<strong>The following errors were processed during your request:</strong>
<br />
<em>&bull; Length input was submitted as 0.</em>"
;
elseif (empty($_REQUEST['value']))
$error "
<strong>The following errors were processed during your request:</strong>
<br />
<em>&bull; Length input was left empty.</em>"
;
else
$error "
<strong>An error processed with your request.</strong>"
;

echo $error;
return;
 }

echo 
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="author" content="ccbtimewiz" />
<title>Password Generator</title></head>'
;

if (!isset($_REQUEST['usenums']) && !isset($_REQUEST['usecaps']) && !isset($_REQUEST['uselower']) && !isset($_REQUEST['usesymbols']))
 {
$_REQUEST['usenums'] = true;
$_REQUEST['usecaps'] = true;
$_REQUEST['uselower'] = true;
$_REQUEST['usesymbols'] = false;
 }

if (!isset($_REQUEST['value']))
$keepalive true;

echo 
'
<body>
<div align="left" style="padding: 2px;">
<span style="font-size: 140%">Password Generator</span><br />
<span style="font-size: 80%">Want a random password? Just fill out this form and click &quot;Generate Password&quot;!</span><br /><br />
<form action="' 
$_SERVER['SCRIPT_NAME'] . '" method="post">
<label><input type="checkbox" name="usenums" ' 
, ($_REQUEST['usenums'] && !$keepalive) ? 'checked="checked"' '' ' /> Include numbers?</label>
<br />
<label><input type="checkbox" name="usecaps" ' 
, ($_REQUEST['usecaps'] && !$keepalive) ? 'checked="checked"' '' ' /> Include capital letters?</label>
<br />
<label><input type="checkbox" name="uselower" ' 
, ($_REQUEST['uselower'] && !$keepalive) ? 'checked="checked"' '' ' /> Include lowercase letters?</label>
<br />
<label><input type="checkbox" name="usesymbols" ' 
, ($_REQUEST['usesymbols'] && !$keepalive) ? 'checked="checked"' '' ' /> Include symbols/special characters?</label>
<br />
<label>Password length:&nbsp;&nbsp;<input type="text" name="value" value="' 
. (!empty($_REQUEST['value']) ? $_REQUEST['value'] : '') . '" maxlength="3" size="5" /></label><br />
<br />
<input value="Generate Password" type="submit" />
</form><br />'
;

generate_pass();

echo 
'
</div>
</body>
</html>'
;

?>

Live: http://jeunosky.net/passgen.php
« Last Edit: February 02, 2009, 08:50:24 pm by ccbtimewiz »

Offline [JeReMy]

  • SMF For Free Master
  • *
  • Posts: 1174
  • www.ourhangout.org
    • View Profile
    • ourhangout

  • Total Badges: 16
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: PHP Random Pass Generator Script
« Reply #1 on: January 09, 2009, 10:47:09 pm »
it generates a password for what?

Offline Colette Brunel

  • SMF For Free Sr. Member
  • *
  • Posts: 424
    • View Profile

  • Total Badges: 17
    Badges: (View All)
    Poll Voter Level 4 Fourth year Anniversary Windows User Topic Starter
Re: PHP Random Pass Generator Script
« Reply #2 on: January 09, 2009, 10:47:47 pm »
A random password. Eg, a pass you could use for something if you can't think of anything good.

Offline -Sя.Sharp

  • SMF For Free Master
  • *
  • Posts: 1032
    • View Profile
    • Hidden Designers

  • Total Badges: 19
    Badges: (View All)
    Topic Starter Combination Level 4 Level 3 Level 2
Re: PHP Random Pass Generator Script
« Reply #3 on: January 09, 2009, 10:51:35 pm »
Very nice :D

Offline [JeReMy]

  • SMF For Free Master
  • *
  • Posts: 1174
  • www.ourhangout.org
    • View Profile
    • ourhangout

  • Total Badges: 16
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: PHP Random Pass Generator Script
« Reply #4 on: January 10, 2009, 10:26:41 am »
ahh i see COOL!

Offline [JeReMy]

  • SMF For Free Master
  • *
  • Posts: 1174
  • www.ourhangout.org
    • View Profile
    • ourhangout

  • Total Badges: 16
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: PHP Random Pass Generator Script
« Reply #5 on: January 10, 2009, 10:47:56 am »
where do you enter this at?

Offline - Lawrence -

  • SMF For Free Hero
  • *
  • Posts: 549
    • View Profile

  • Total Badges: 15
    Badges: (View All)
    Topic Starter Combination Level 3 Level 2 Level 1
Re: PHP Random Pass Generator Script
« Reply #6 on: January 15, 2009, 02:46:32 pm »
Wow cool code. ;) Is is completely random?

Offline php coder

  • SMF For Free Newbie
  • *
  • Posts: 16
    • View Profile
    • YOUR NUMBER 1 RSPS STATUS PAGE!

  • Total Badges: 10
    Badges: (View All)
    Topic Starter Combination Level 2 Level 1 10 Posts
Re: PHP Random Pass Generator Script
« Reply #7 on: January 15, 2009, 03:12:04 pm »
very nice code.
 :D

Offline Colette Brunel

  • SMF For Free Sr. Member
  • *
  • Posts: 424
    • View Profile

  • Total Badges: 17
    Badges: (View All)
    Poll Voter Level 4 Fourth year Anniversary Windows User Topic Starter
Re: PHP Random Pass Generator Script
« Reply #8 on: February 02, 2009, 08:03:00 pm »
I've completely revamped the script to be more "user friendly" and feature-esque. View the first post to see the updates.

 

Related Topics

  Subject / Started by Replies Last post
7 Replies
1998 Views
Last post March 30, 2007, 07:17:35 pm
by Megazero
3 Replies
1592 Views
Last post October 16, 2007, 11:56:23 am
by nickrulz1
1 Replies
1302 Views
Last post June 12, 2009, 10:48:22 am
by simply sibyl
1 Replies
1179 Views
Last post August 03, 2009, 03:24:10 pm
by simply sibyl