Last active
December 17, 2015 17:08
-
-
Save fhferreira/5643325 to your computer and use it in GitHub Desktop.
Generator for randomic passwords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class PasswordGenerator{ | |
/** | |
* @param integer $length | |
* @return string $pass | |
* @author Flávio Henrique Ferreira <[email protected]> | |
**/ | |
static function randomPassword($length = 8) | |
{ | |
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789#!@$%"; | |
$password = array(); | |
$alphaLength = strlen($alphabet) - 1; | |
for ($i = 0; $i < $length; $i++) | |
{ | |
$n = rand(0, $alphaLength); | |
$password[] = $alphabet[$n]; | |
} | |
/* | |
* turn the array into a string | |
*/ | |
return implode($password); | |
} | |
} | |
/*Usage*/ | |
$pass = PasswordGenerator::randomPassword(24); //24 characters | |
$pass = PasswordGenerator::randomPassword(); //8 characters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment