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:
@@ -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())) {
|
||||
|
||||
Reference in New Issue
Block a user