大佬教程收集整理的这篇文章主要介绍了php-laravel 4 auth :: attempt纯文本密码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
您如何告诉laravel auth :: attempt密码字段以明文存储,而不是假设它是散列的?
附带guard.PHP
public function attempt(array $credentials = array(), $remember = false, $login = true)
{
$this->fireAttemptEvent($credentials, $remember, $login);
$user = $this->provider->retrieveByCredentials($credentials);
// If an implementation of UserInterface was returned, we'll ask the provider
// to validate the user against the given credentials, and if they are in
// fact valid we'll log the users into the application and return true.
if ($user instanceof UserInterface)
{
if ($this->provider->validateCredentials($user, $credentials))
{
if ($login) $this->login($user, $remember);
return true;
}
}
return false;
}
或更好的是,我只有两列,一列为纯文本,另一列为password_secured.
如果我尝试使用后者,我如何告诉尝试密码列名称为password_secured.
因为我尝试了此操作,但收到错误未定义索引:密码.
$user = array(
'user_id' => Input::get('username'),
'password_secured' => Input::get('password'),
'checklogin' => 0,
);
if (Auth::attempt($user)) {
return 'login success';
}
关键是我正在移植应用程序,而不是从头开始构建,而且我确实需要将密码以明文形式存储,因为另一个应用程序正在使用DB(并且它是活动的)并且被编码为以明文形式读取密码.
解决方法:
考虑运行一个脚本来对所有密码进行哈希处理:绝对不要强制甚至考虑以纯文本方式存储(即使您继承了系统),因为一旦数据库内容泄漏,这些密码就会立即丢失.骇客发生.想象一下,如果您的客户发现您未按照标准处理他们的数据,那么诉讼….
现在,假设您不想听这个警告,那么执行该操作的方法会有些破绽,但却可以解决.从源头上看(寻找__construct),Guard被赋予了一个实现UserProviderInterface的对象.
您有一堆合适的对象.选择一个您想要的,并扩展它.我们将对DatabaseUserProvider感到一些乐趣,尽管此扩展方法非常方便并且对所有其他用户都可行.
我们将要扩展的方法是公共函数validateCredentials(UserInterface $user,数组$credentials).如下:
namespace Illuminate\Auth;
class MyUserInterface extends DatabaseUserProvider {
public function validateCredentials(UserInterface $user, array $credentials) {
$plain = $credentials['password'];
return ($plain === $user->getAuthPassword());
}
}
随着MyUserInterface扩展本身提供UserProviderInterface的DatabaseUserProvider,MyUserInterface现在可以在Guard中作为提供程序进行依赖项注入.我们已经完成了一半的工作.下一步是实际告诉Guard加载您的东西.我不熟悉Laravel4加载Guard实现的方式,但是在配置的某个地方,您可以将MyUserInterface设置为首选的Guard接口.我不能比这更具体.
顺便说一句,该类需要与Auth的其他接口实现位于相同的位置.
以上是大佬教程为你收集整理的php-laravel 4 auth :: attempt纯文本密码全部内容,希望文章能够帮你解决php-laravel 4 auth :: attempt纯文本密码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。