【问题标题】:Laravel-5: Can't get Auth::attempt to succeedLaravel-5:无法获得 Auth::attempt 成功
【发布时间】:2015-05-17 04:35:42
【问题描述】:

我的app.php

/*
    |--------------------------------------------------------------------------
    | Default Authentication Driver
    |--------------------------------------------------------------------------
    |
    | This option controls the authentication driver that will be utilized.
    | This driver manages the retrieval and authentication of the users
    | attempting to get access to protected areas of your application.
    |
    | Supported: "database", "eloquent"
    |
    */

    'driver' => 'database',

    /*
    |--------------------------------------------------------------------------
    | Authentication Model
    |--------------------------------------------------------------------------
    |
    | When using the "Eloquent" authentication driver, we need to know which
    | Eloquent model should be used to retrieve your users. Of course, it
    | is often just the "User" model but you may use whatever you like.
    |
    */

    'model' => 'App\Model\Member',

    /*
    |--------------------------------------------------------------------------
    | Authentication Table
    |--------------------------------------------------------------------------
    |
    | When using the "Database" authentication driver, we need to know which
    | table should be used to retrieve your users. We have chosen a basic
    | default value but you may easily change it to any table you like.
    |
    */

    'table' => 'members',

我的模特:

类成员扩展模型实现 Authenticatable {

protected $fillable = [];

/**
 * The database table used by the model.
 *
 * @var string
 */
protected $table = 'members';

protected $primaryKey = 'id';

/**
 * Get the unique identifier for the user.
 *
 * @return mixed
 */
public function getAuthIdentifier()
{
    return $this->getKey();

}

/**
 * Get the password for the user.
 *
 * @return string
 */
public function getAuthPassword()
{
    return $this->password;
}

/**
 * Get the token value for the "remember me" session.
 *
 * @return string
 */
public function getRememberToken()
{
    // TODO: Implement getRememberToken() method.
}

/**
 * Set the token value for the "remember me" session.
 *
 * @param  string $value
 * @return void
 */
public function setRememberToken($value)
{
    // TODO: Implement setRememberToken() method.
}

/**
 * Get the column name for the "remember me" token.
 *
 * @return string
 */
public function getRememberTokenName()
{
    // TODO: Implement getRememberTokenName() method.
}

}

正在尝试 Auth:attempt(....

 if (Auth::attempt(array('email' => Request::input('email'), 'password' => Request::input('password'))))
            {
                echo ("SUCCESS");
                Auth::logout();
            }
            else
            {
                echo ("FAILED");
            }

这总是“失败”。如果我进行Member::where.... 搜索,我将正确获取记录,因此我知道模型和数据库都可以。

为什么 Auth::attempt 失败?我确保电子邮件和密码正确并存在于数据库中。

【问题讨论】:

  • 只是为了确保尝试更改 config/auth.php 并设置 'table' = 'members' 看看它是否有效
  • 您是否正确地散列了密码?
  • 我相信这就是问题所在。我没有使用任何密码散列,认为这将是最简单的情况。我错了。当我使用 Hash::make(.....) 保存密码时,Auth::attempt 有效。
  • user2094178 如果您将此作为答案提交,我会感谢您。谢谢。

标签: laravel laravel-5


【解决方案1】:

Auth::attempt() 要求使用Hash::make($password)bcrypt($password) 对存储在数据库中的密码进行哈希处理。

【讨论】:

    猜你喜欢
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 2015-12-10
    • 2019-05-21
    • 2014-12-17
    • 2023-03-05
    相关资源
    最近更新 更多