laravel 4 sentry 2如何更改密码和rehash

时间:2013-12-17 22:50:12

标签: php laravel cartalyst-sentry

在我的应用程序中,有一个视图允许登录用户输入新密码。我如何散列新密码?使用原生Laravel Auth我只会

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

Sentry 2是否相同?如果是,在执行重置并更新用户表后,我得到WrongPasswordException,所以我假设哈希方法不同。如果Sentry有自己的哈希方法,我肯定找不到它。

更新:显然this method将以相同的方式运行并自动保存用户记录,文档只是不指出这一点。

1 个答案:

答案 0 :(得分:3)

使用Sentry方法更新用户,它会自动将密码哈希为Sentry::getUserProvider()->create();

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.';
    }