简体   繁体   中英

laravel 4 sentry 2 how to change password and rehash

In my app there's a view that allows the logged in user to enter a new password. How am I to hash the new password? Using native Laravel Auth I would just

Hash::make($input['password']);

is it the same for Sentry 2 ? If it is, after performing a reset and updating the user table I get a WrongPasswordException so I'm assuming the hash methods are different. If Sentry has it's own hash method, I sure can't find it.

Update: Apparently this method will work the same way and auto-save the user record, the docs just don't point that out.

Update the user using the Sentry methods, it will automatically hash the password as Sentry::getUserProvider()->create(); do.

try
    {
        // Find the user using the user id
        $user = Sentry::findUserById(1);

        // Update the user details
        $user->email = 'john.doe@example.com';
        $user->first_name = 'John';

        // Update the user
        if ($user->save())
        {
            // User information was updated
        }
        else
        {
            // User information was not updated
        }
    }
    catch (Cartalyst\Sentry\Users\UserExistsException $e)
    {
        echo 'User with this login already exists.';
    }
    catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
    {
        echo 'User was not found.';
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM