//php
function generate_random_password() {
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$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
}
//php
//Jquery
$('#generate_password_button').on('click', function () {
var password = "";
password = generate_random_password();
$('#generate_password_label').text(password);
$('#password').val(password);
$('#confirm_password').val(password);
});
function generate_random_password() {
var chars = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()-+<>ABCDEFGHIJKLMNOP1234567890";
var password = "";
for (var x = 0; x < 8; x++) {
var i = Math.floor(Math.random() * chars.length);
password += chars.charAt(i);
}
return password;
}
//Jquery