Password Generator Example
Php / / July 04, 2021
The following code will will generate a password on PHP, between a range of 5 and 12 characters, which you can also modify.
It comes in handy when making a user system, in the part where a user forgets his password, so can generate a password and send it to your email and save it in the database, if you have the passwords encrypted.
Code:
# For Example Of. Com
function generatePassword ($ characters) {
$ password = "";
$ characters = "0123456789bcdfghjkmnpqrstvwxyz!" # $% & / () =?,;.: -_} {*] [* - + / ";
$ i = 0;
$ while ($ i $ char = substr ($ characters, mt_rand (0, strlen ($ characters) -1), 1)
if (! strstr ($ password, $ char)) {
$ password. = $ char
$ i ++;
}
}
return password;
}
$ amountchar = rand (5, 12);
$ password = generatePassword ($ amountchar);
echo "The generated password is:". $ password. "";
threw out "
Courtesy of Example of. Com";
?>