Reputation: 772
Hello I am working with Codeigniter and I want to generate the random password.
I developed signup functionality using
crypt($password)
login functionality check password following.
if (crypt($password, $hashed_password) === $hashed_password)
{
return $query->result();
}
I am developing Forgot functionality.
How to send random generated password to user mail When I am using crypt() login time.
Upvotes: 2
Views: 11773
Reputation: 1
We can do this without using array or for loop. Using inbuilt function.
function random_password($length = 8) {
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+=-<>?/,.';
$password = str_shuffle($alphabet);
return substr($password, 0, $length);
}
echo random_password(10);
Upvotes: 0
Reputation: 947
You can try below function to generate random password.
function random_password()
{
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$password = array();
$alpha_length = strlen($alphabet) - 1;
for ($i = 0; $i < 8; $i++)
{
$n = rand(0, $alpha_length);
$password[] = $alphabet[$n];
}
return implode($password);
}
echo random_password();
Upvotes: 6