Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 4 - Shield - Change password
#1

(This post was last modified: 12-19-2022, 08:51 AM by superior.)

Hi,
In my project i've started writing a change password functionality for the users, this is checked by confirming the current password.
Reading through the documentation i'm unable to find what method/helper I can use to run the current password check against the user.
Using the login example does not work, it throws an exception about the session already being active, so i have no clue what to use at this point.

Can someone push me in the right direction?


EDIT:
Did not look at all possible options, you can use the check() method to do that.
See: https://codeigniter4.github.io/shield/au...uth-helper
Reply
#2

Another way is to use magic-link. In this method, the user uses magic-link to login and after logging in, it is checked that it is done by logging in through magic-link and it is used to change the password.
It is possible to use session or events in this method.(magicLogin)

https://codeigniter4.github.io/shield/qu...ink-logins
Reply
#3

Thank you for the suggestion, but the check actually does everything i've needed for this part.
I've written a custom validation rules 'old_password' that will check the current password for the user.

If anyone is interested on how this is done:

PHP Code:
public function old_password(string $password, ?string &$error null): bool
{
    $result auth()->check([
        'email'    => auth()->user()->email,
        'password' => $password,
    ]);

    if( !$result->isOK() ) {
        // Send back the error message
        $error lang('Auth.errorOldPassword');

        return false;
    }

    return true;

Reply




Theme © iAndrew 2016 - Forum software by © MyBB