Show DevBest [PHP] [REL] Password Generator Script

Status
Not open for further replies.

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Earlier on today I released a PHP password generator that I created and a few people asked for the source codes to it -- I am not releasing the FULL site, but what I will release is the function I had created to generate the functions.

Use it as you wish, I'm not bothered about credits, but it would be nice!

Function:
PHP:
function GeneratePassword( $l, $s, $n, $uc, $lc )
{
/** ABOUT THE PARAMETERS
 * $l  - integer - length of the password to be generated
 * $s  - integer - include symbols in the password (VALUES: '1' or '0' -- 1=yes, 0=no)
 * $n  - integer - include numbers in the password (VALUES: '1' or '0' -- 1=yes, 0=no)
 * $uc - integer - include upper-case characters in the password (VALUES: '1' or '0' -- 1=yes, 0=no)
 * $lc - integer - include lower-case characters in the password (VALUES: '1' or '0' -- 1=yes, 0=no)
 */

$symbols               = "¬!\"£$%^&*()_+{}:@~<>?`-=[];'#,./";
$numbers               = "1234567890";
$upper                 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$lower                 = "abcdefghijklmnopqrstuvwxyz";
$characters_to_include = "";
$password              = "";

if ( $s == "1" ) $characters_to_include .= $symbols;
if ( $n == "1" ) $characters_to_include .= $numbers;
if ( $uc == "1" ) $characters_to_include .= $upper;
if ( $lc == "1" ) $characters_to_include .= $lower;

/*none selected*/
if ( !$s || !$n || !$uc || !$lc ) $characters_to_include = $numbers . $upper . $lower;
/*none selected*/

for( $p = 1; $p <= $l; $p++ )
{
$password .= substr( $characters_to_include, mt_rand( $p, strlen( $characters_to_include ) ), 1 );
}
return htmlentities( $password );
}

Usage:
PHP:
<?php
echo GeneratePassword( 7, 0, 1, 1, 1 );
?>

Result:
Will generate a 7 digit long password consisting of numbers, lower-case and upper-case letters.

Enjoy,
m0nsta.
 

TesoMayn

Boredom, it vexes me.
Oct 30, 2011
1,482
1,482
I am going to put this on my site, and definitely include credits. So what would you like your link to point to?
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Glad you like it enough to use it!

And if you put credits, link it to please.
 
Status
Not open for further replies.

Users who are viewing this thread

Top