delight-im / PHP-Auth

Authentication for PHP. Simple, lightweight and secure.
MIT License
1.08k stars 234 forks source link

$auth->forgotPassword creates fatal error #290

Closed triumphhub closed 1 year ago

triumphhub commented 1 year ago

Hello Forum,

Great work but the password reset is throwing an error: "PHP Fatal error: Uncaught Delight\Db\Throwable\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0' for key 'PRIMARY' in *//**/delight-im/db/src/ErrorHandler.php:66,"

Everything else works excellently.

Here is my code:

try {
    $auth->forgotPassword($_POST['email'], function ($selector, $token) {
    });

    echo 'Request has been generated';
}
catch (\Delight\Auth\InvalidEmailException $e) {
    die('Invalid email address');
}
catch (\Delight\Auth\EmailNotVerifiedException $e) {
    die('Email not verified');
}
catch (\Delight\Auth\ResetDisabledException $e) {
    die('Password reset is disabled');
}
catch (\Delight\Auth\TooManyRequestsException $e) {
    die('Too many requests');
}

Any help greatly appreciated.

triumphhub commented 1 year ago

I fixed the problem. There was no AI set on the id column of the users_resets table. Maybe a legacy issue. I set AI on the id column to fix.

ocram commented 1 year ago

Thanks for sharing the cause of this problem for you. AI being AUTO_INCREMENT, of course. Perhaps make sure your database schema is consistent with the one from this library in all the remaining parts, to avoid future bugs in other areas.