【问题标题】:laravel 4 sentry 2 how to change password and rehashlaravel 4 sentry 2 如何更改密码和重新散列
【发布时间】:2013-12-17 22:50:11
【问题描述】:

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

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

Sentry 2 也一样吗?如果是这样,在执行重置并更新用户表后,我会得到一个WrongPasswordException,所以我假设哈希方法不同。如果 Sentry 有自己的 hash 方法,我肯定找不到。

更新:显然this method 会以同样的方式工作并自动保存用户记录,只是文档没有指出这一点。

【问题讨论】:

  • UserModel::$password 上似乎有一个 Mutator,它会根据配置中设置的 Hasher 自动对密码进行哈希处理。

标签: php laravel cartalyst-sentry


【解决方案1】:

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

【讨论】:

  • 当我一秒钟前自己想通了这个。文档应该提及该逻辑。
  • @JaredEitnier 我和你一样,Sentry 的文档缺少它:/
猜你喜欢
  • 2013-10-13
  • 2014-04-06
  • 2015-05-24
  • 2013-10-29
  • 1970-01-01
  • 2014-03-31
  • 1970-01-01
  • 2014-12-10
  • 1970-01-01
相关资源
最近更新 更多