Laravel 5 在laravel 5身份验证中使用普通密码,而不是bcrypt

Laravel 5 在laravel 5身份验证中使用普通密码,而不是bcrypt,laravel-5,Laravel 5,我在一个后端应用程序中使用了laravel bcrypt身份验证,但客户端要求普通密码身份验证,这样他就可以看到作为管理员的每个用户的密码。我的整个应用程序逻辑都基于laravel内置的身份验证方法,即bcrypt哈希。如何用存储在数据库中的普通密码mach代替存储哈希来替换它以进行身份验证?在laravel 4中,您可以重写哈希模块。这说明了如何使用SHA1而不是bycrypt[检查接受的答案和注释] 您可以使用此处介绍的方法保存密码,而无需散列。在laravel 4中,您可以重写散列模块。这

我在一个后端应用程序中使用了laravel bcrypt身份验证,但客户端要求普通密码身份验证,这样他就可以看到作为管理员的每个用户的密码。我的整个应用程序逻辑都基于laravel内置的身份验证方法,即bcrypt哈希。如何用存储在数据库中的普通密码mach代替存储哈希来替换它以进行身份验证?

在laravel 4中,您可以重写
哈希
模块。这说明了如何使用SHA1而不是bycrypt[检查接受的答案和注释]


您可以使用此处介绍的方法保存密码,而无需散列。

在laravel 4中,您可以重写
散列
模块。这说明了如何使用SHA1而不是bycrypt[检查接受的答案和注释]


您可以使用此处介绍的方法保存密码,而无需散列。

好吧,这确实会危及您客户的网站安全。 不建议在数据库中存储普通密码。如果有人访问了数据库,他/她的站点将非常容易受到攻击,任何拥有数据库副本的人都可以轻松访问所有类型的帐户。我坚持认为您应该创建重置/更改密码功能,而不是在数据库中存储普通密码。 不管怎样,你只需要使用

$password = Input::get('password');
我想你可以用

if (Auth::attempt(array('password' => $password)))
{
    return Redirect::route('home');
}

那真的会危及你客户的网站安全。 不建议在数据库中存储普通密码。如果有人访问了数据库,他/她的站点将非常容易受到攻击,任何拥有数据库副本的人都可以轻松访问所有类型的帐户。我坚持认为您应该创建重置/更改密码功能,而不是在数据库中存储普通密码。 不管怎样,你只需要使用

$password = Input::get('password');
我想你可以用

if (Auth::attempt(array('password' => $password)))
{
    return Redirect::route('home');
}

如果您现在使用的是Laravel 5^,那么可以通过搜索类illumb/Auth/EloquentUserProvider并在其中进行一些小的调整来实现这一点

例如,查找公共函数retrieveByCredentials()和validateCredentials()。在第二个函数中,您可以看到laravel正在检查要输入Auth::true()方法的散列密码。只要将其更改为普通检查,您就完成了

 public function retrieveByCredentials(array $credentials)
{
    if (empty($credentials)) {
        return;
    }

    // First we will add each credential element to the query as a where clause.
    // Then we can execute the query and, if we found a user, return it in a
    // Eloquent User "model" that will be utilized by the Guard instances.

    $query = $this->createModel()->newQuery();

    foreach ($credentials as $key => $value) {
        if (! Str::contains($key, 'password')) {
            $query->where($key, $value);
        }
    }

    return $query->first();
}

/**
 * Validate a user against the given credentials.
 *
 * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
 * @param  array  $credentials
 * @return bool
 */
public function validateCredentials(UserContract $user, array $credentials)
{
    $plain = $credentials['password'];

    return $this->hasher->check($plain, $user->getAuthPassword());
}

将$this->hasher->check更改为普通检查,您就完成了。:)

如果您现在使用的是Laravel 5^,您可以通过搜索类illumb/Auth/EloquentUserProvider并在其中进行一些小的调整来实现这一点

例如,查找公共函数retrieveByCredentials()和validateCredentials()。在第二个函数中,您可以看到laravel正在检查要输入Auth::true()方法的散列密码。只要将其更改为普通检查,您就完成了

 public function retrieveByCredentials(array $credentials)
{
    if (empty($credentials)) {
        return;
    }

    // First we will add each credential element to the query as a where clause.
    // Then we can execute the query and, if we found a user, return it in a
    // Eloquent User "model" that will be utilized by the Guard instances.

    $query = $this->createModel()->newQuery();

    foreach ($credentials as $key => $value) {
        if (! Str::contains($key, 'password')) {
            $query->where($key, $value);
        }
    }

    return $query->first();
}

/**
 * Validate a user against the given credentials.
 *
 * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
 * @param  array  $credentials
 * @return bool
 */
public function validateCredentials(UserContract $user, array $credentials)
{
    $plain = $credentials['password'];

    return $this->hasher->check($plain, $user->getAuthPassword());
}

将$this->hasher->check更改为普通检查,您就完成了。:)

哇,这些都太复杂了,就这么简单

if ($user = User::where('email', request()->email)->where('password', request()->password)->first()) {
    Auth::login($user);
    return redirect()->to('/');
}

虽然我同意在生产环境中不应该这样做。但是我可以看到,对于一些应用程序,如果用户知道密码是以纯文本形式存储的,这可能没问题。

哇,这些都很复杂,很简单

if ($user = User::where('email', request()->email)->where('password', request()->password)->first()) {
    Auth::login($user);
    return redirect()->to('/');
}

虽然我同意在生产环境中不应该这样做。但是我可以看到,对于某些应用程序,如果用户知道密码是以纯文本形式存储的,那么它可能是正常的。

不,不会。我和我的团队讨论过。他们说在某种程度上隐私并不重要D搞笑:我应该写哪个文件?对不起,如果是基本的。我是新来的拉威尔。不用担心:)我们都是从某个地方开始的。在处理验证以检查Auth:attemp()的控制器/存储库中,在处理注册码而不是散列密码的控制器中,只需使用普通输入::get方法。不,它不会。我和我的团队讨论过。他们说在某种程度上隐私并不重要D搞笑:我应该写哪个文件?对不起,如果是基本的。我是新来的拉威尔。不用担心:)我们都是从某个地方开始的。在处理验证以检查Auth:attemp()的控制器/存储库中,在处理注册码而不是散列密码的控制器中,只需使用普通输入::get方法即可。在应用程序中完全验证::check()请尝试使用if(Auth::check())Hey{{{Auth::user()->name}endif除非(Auth::check())的刀片模板您尚未登录。endUnlessly Auth::check()在应用程序中尝试使用if(Auth::check())Hey{{{Auth::user()->name}}endif作为刀片模板,除非(Auth::check())您未登录。结束语