Php 基本laravel身份验证无法登录

Php 基本laravel身份验证无法登录,php,authentication,laravel,Php,Authentication,Laravel,我有id和密码,在表帐户中。我将使用id和密码登录。结果很糟糕 auth.php 'driver' => 'database', 'model' => 'Pass', 'table' => 'account', models/Pass.php use Illuminate\Auth\UserTrait; use Illuminate\Auth\UserInterface; use Illuminate\Auth\Reminders\RemindableTrait; use I

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

auth.php

'driver' => 'database',
'model' => 'Pass',
'table' => 'account',
models/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';
PassController.php

public function authenticate()
{
$userdata = array( 'id' => Input::get('id'), 'password' => Input::get('password'));
    if(Auth::attempt($userdata)) 
    {
        echo 'oke';
    } 
    else 
    {
        echo 'bad';
    }
}
在视图中

{{Form::open(array('action' => 'PassController@authenticate')) }}
...
routes.php

Route::post('book/auth', 'PassController@authenticate');

如何解决这个问题?我使用的是Laravel4.2,你绝对应该这样做,不,你基本上必须散列存储密码。在数据库中使用纯文本密码是一个主要的安全风险

现在,显然在创建新用户时需要对密码进行哈希运算。(在您的注册控制器或类似设备中)

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

php artisan tinker
> echo Hash::make('your-secret-password');
然后复制散列并在数据库中更新它

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

更新 请尝试此项进行测试:

public function authenticate()
{
    $user = Pass::find(Input::get('id'));
    if(Hash::check(Input::get('password'), $user->password))
    {
        echo 'oke';
    } 
    else 
    {
        echo 'bad';
    }
}
更新2 如果您的哈希密码列名为
hashd\u pass
(或
password
以外的任何内容),您需要在模型中指定:

public function getAuthPassword()
{
    return $this->hashed_pass;
}

查看config文件夹中的auth.php。您应该将
user
表更改为
account
tableyes,auth.php,如上所述为什么要使用id和密码登录?如果您有id,则可以使用以下方法登录。它不需要密码。Auth::loginUsingId(输入::get('id');作为用户名和密码的id仍然是密码。如果用户名和密码匹配,登录成功使用模型进行身份验证您应该使用“雄辩”身份验证驱动程序
,这样您只需转到URL/hash/your secret password,它就会输出该密码的哈希值。然后将其复制并在数据库中更新。
这本身就是一个重大的安全风险。访问它会将密码放入纯文本Web服务器日志中(如果您有类似Google Analytics的内容,也可以)。最好使用
php artisan tinker
来做这件事。@ceejayoz我只是建议开发时使用它。但是我显然忘了提到。。。将我的答案更改为
php artisan tinker
。谢谢。@lukasgeiter是否可以查看并保存humanic密码?例如:我有humanic password的Column password,并传递散列的humanic password的\u散列。您可以但不应该这样做。密码应该以散列方式存储,这样即使您的数据库遭到破坏,密码也不会被发现。您这样做有什么原因吗?如果表单提交的用户名和密码将被删除(业务角色),我将创建许多用户名、密码并提供给用户以登录表单页面