Enhance authentication logic for customers with default passwords

- Added a check to ensure customers with group ID other than 0 cannot use default passwords.
- Implemented logic to auto-set passwords to the last 4 digits of the customer number if no password is set.
- Updated method documentation to include an `@throws Exception` annotation.
This commit is contained in:
Jeppe Bundgaard
2025-10-28 11:06:18 +01:00
parent d06f0cedc3
commit af6b89ff54
+11 -1
View File
@@ -11,6 +11,9 @@ use objects\users_o;
class authentication implements authentication_i
{
/**
* @throws Exception
*/
public function authenticate(int $customer_number, string $password): bool
{
// Get the customer from the database
@@ -21,7 +24,14 @@ class authentication implements authentication_i
}
// Check if the customer has a password
if (!$customer->hasPassword()) {
return false;
// Make sure the customer group is 0, to prevent higher privilege users from accessing the system through the default password.
if ((int)$customer->group_id->value() !== 0) {
return false;
}
// Does have a customer number, set the password to the last 4 digits of the customer number
if (!empty($customer->customer_number->value()) && strlen($customer->customer_number->value()) > 4) {
$customer->setPassword(substr($customer->customer_number->value(), -4));
}
}
// Check if the password is correct
if (!$this->match_passwords($password, $customer->getPassword())) {