I would like to create a random string for every row in my row for the field password - basically its a bulk password generator.
Unfortunately, when I hit the bulk reset button the passwords are reset to all the same string. I would like to have a different random string for each row.
Here is my code:
echo '<form method="post" action=""><input type="submit" name="bulk_password_reset" value="Bulk Password Reset" /></form>';
if (isset($_POST['bulk_password_reset'])) {
$password = generateRandomString();
while ($result = $sqlUpdate->fetch()) {
$sqlUpdate = $dbh->prepare("UPDATE $tableName SET password = :password");
$sqlUpdate-> execute(array(':password'=>$password));
$sqlUpdate->execute();
header('Location: su_password_reset.php');
}
}
Here is my random string generator function:
//Generate random password
function generateRandomString($length = 10) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
What am I doing wrong please?