Passwords. Used everywhere, passwords can also be a part of your Codeigniter application. So they are a part of InvoicePlane, that is based on Codeigniter. To provide password suggestions for the installation process I thought about a simple yet secure solution.
/**
* Generates a random password
* @return string
**/
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
Or
/**
* Generates a random password
* @return string
**/
function generate_password_suggestion()
{
$chars = "abcdefghijklmnpqrstuvwxyzABCDEFGIHJKLMNPQRSTUVWXYZ123456789-_";
$suggestion = substr(str_shuffle($chars), 0, 12);
return $suggestion;
}
Nguồn : Sưu tập