we're a payment gateway, similar to PayPal, each user requires an account and recently we've been having resourcing issues from the create account process.
We have narrowed down that it's our duplicate password security function calling the database that's grinding the system to a halt.
We have provided the code for the function below. There are >500,000 rows in the user_accounts
table. Is there anything we can do to optimise this function?
P.S. We understand that SHA1 is a deprecated way of storing passwords, we are considering upgrades.
function duplicate_passwd_check($users_password) {
$pass_array = $sql->fetch("SELECT * FROM user_accounts");
foreach ($pass_array as $db_key => $db_value) {
// perform hashing
$salt = md5($users_password . SITE_PEPPER);
$hashed_users_password = sha1($users_password . $salt);
// perform check
if ($db_value['hashed_password'] == $hashed_users_password) {
$error->add("Password already in use, please use a different one.");
locate("register"); // redirect to register page
}
}
return 0;
}