I’ve recently added a class which uses unique salts stored in the members table. This was my login script before I used salts:
$sql = 'SELECT id, username FROM member WHERE username = ? AND pass = ?';
$result = $this->DB->query($sql, array($username, $pass));
foreach($result as $record) {
$user = [
"id" => $record['id'],
"username" => $record['name']];
}
if (empty($user)) {
// Display errors
} else {
// Login by sending the array of data to login function
self::login($user);
}
Now, I want to get the salts too. Is there any way I can do this without using more than 1 query? I can make it work by starting with a query to get the user pass and salt but is there a better way. It feels kind of like a hack or is it simply unavoidable?
You may do (assuming the
passis created asMD5($salt . $password)and that you have column namedsaltinside yourmembertable):This way MySQL directly checks stored hash created after
CONCAT-ing inserted password and salt.