2013-12-17 41 views
1

在我的应用程序中有一个视图,允许登录用户输入新密码。我如何散列新密码?使用本机Laravel Auth我只想laravel 4哨兵2如何更改密码和重新编号

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

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

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

+0

看起来'UserModel :: $ password'上有一个Mutator,它根据配置中的哈希集合自动哈希密码。 – Goldentoa11

回答

3

更新用户使用Sentry方法,它会自动散列密码为Sentry::getUserProvider()->create();做。

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

当我第二次以前自己弄明白了这一点。文档应该提及一些关于该逻辑的内容。 –

+0

@JaredEitnier我和你一样,Sentry的文档缺乏它:/ –