基本 Laravel 身份验证无法登录

ka *_*ern 3 php authentication laravel

我有 ID 和密码,在表帐户中。我将使用 ID 和密码登录。而且结果很糟糕

验证文件

'driver' => 'database',
'model' => 'Pass',
'table' => 'account',
Run Code Online (Sandbox Code Playgroud)

模型/Pass.php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class Pass extends \Eloquent implements UserInterface, RemindableInterface 
{
    use UserTrait, RemindableTrait;

protected $table = 'account';
Run Code Online (Sandbox Code Playgroud)

PassController.php

public function authenticate()
{
$userdata = array( 'id' => Input::get('id'), 'password' => Input::get('password'));
    if(Auth::attempt($userdata)) 
    {
        echo 'oke';
    } 
    else 
    {
        echo 'bad';
    }
}
Run Code Online (Sandbox Code Playgroud)

在视图中

{{Form::open(array('action' => 'PassController@authenticate')) }}
...
Run Code Online (Sandbox Code Playgroud)

路线.php

Route::post('book/auth', 'PassController@authenticate');
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?我用的是 Laravel 4.2

luk*_*ter 5

你绝对应该这样做,不,你基本上必须存储散列的密码。在数据库中使用纯文本密码是一个主要的安全风险。

现在显然您需要在创建新用户时对密码进行哈希处理。(在您的注册控制器或类似的东西中)。

但是,要手动更改现有密码,您可以使用artisan tinker生成哈希值。

php artisan tinker
> echo Hash::make('your-secret-password');
Run Code Online (Sandbox Code Playgroud)

然后复制哈希并在数据库中更新它。

另请确保数据库中的密码字段长度至少为 60 个字符,否则哈希值将被截断。

更新

尝试这个进行测试:

public function authenticate()
{
    $user = Pass::find(Input::get('id'));
    if(Hash::check(Input::get('password'), $user->password))
    {
        echo 'oke';
    } 
    else 
    {
        echo 'bad';
    }
}
Run Code Online (Sandbox Code Playgroud)

更新2

如果您的散列密码列被称为hashed_pass(或除 以外的任何其他名称password),您需要在模型中指定:

public function getAuthPassword()
{
    return $this->hashed_pass;
}
Run Code Online (Sandbox Code Playgroud)