我在表格帐户中有id和密码。我将使用id和密码登录。结果很糟糕
auth.php
'driver' => 'database',
'model' => 'Pass',
'table' => 'account',
模型/ 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');
如何解决这个问题?我使用laravel 4.2
答案 0 :(得分: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';
}
}
如果您的哈希密码colummn名为hashed_pass
(或password
以外的任何其他内容),则需要在模型中指定:
public function getAuthPassword()
{
return $this->hashed_pass;
}