This is a simple function to Generate random passwords in php applications
/**
* random password generator
* @return type
* @author Arun George <arun@arun-g.in>
* @since 30-09-2013
*/
public function randomPassword()
{
$Inputs = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$password = array(); //declare $password as an array
$aLength = strlen($Inputs) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++)
{
$num = rand(0, $aLength);
$password[] = $Inputs[$num];
}
return implode($password); //turn the array into a string
}
/**
* random password generator
* @return type
* @author Arun George <arun@arun-g.in>
* @since 30-09-2013
*/
public function randomPassword()
{
$Inputs = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$password = array(); //declare $password as an array
$aLength = strlen($Inputs) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++)
{
$num = rand(0, $aLength);
$password[] = $Inputs[$num];
}
return implode($password); //turn the array into a string
}
No comments:
Post a Comment