我被Auth::attempt
困在api。
$credentials = ['user_email' => $data['email'],'user_password' => md5($data['password'])];
if (Auth::attempt($credentials)) {
return Redirect::route("user/profile");
}
<?php
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface{
public $timestamps = false;
protected $table = 'ofalt_users';
protected $hidden = array('password');
protected $primaryKey = 'user_id';
public function getAuthIdentifier()
{
return $this->getKey();
}
public function getAuthPassword()
{
return $this->user_password;
}
public function getReminderEmail()
{
return $this->user_email;
}
}
return array(
'driver' => 'eloquent',
'model' => 'User',
'table' => '',
'reminder' => array(
'email' => 'emails.auth.reminder',
'table' => 'password_reminders',
'expire' => 60,
),
);
它返回ErrorException,因为我使用RESTClient来测试api我无法轻易调试错误。有人可以帮助我。
答案 0 :(得分:1)
Laravel提供
Hash::make()
让您的生活更轻松,
e.g
function postCreateAccount()
{
// validate and messages and whatever you want, if all passes:
$data = Input::all();
User::create(array(
'username' => $data['username'],
'password' => Hash::make($data['password'])
);
}
function postLogin()
{
// validate.... if passes
$data = Input::all();
if(Auth::attempt(array(
'username'=>$data['username'],
'password' => $data['password'])
))
{
return Redirect::to('profile');
}
else
{
return Redirect::to('login');
}
}
你不需要使用MD5,Laravel使用bcrypt,据我所知,在密码方面我知道更好的哈希算法