Jared Eitnier
Jared Eitnier

Reputation: 7152

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.

Upvotes: 1

Views: 3630

Answers (1)

Fernando Montoya
Fernando Montoya

Reputation: 2644

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 = '[email protected]';
        $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.';
    }

Upvotes: 3

Related Questions