Laravel Auth ::尝试

时间:2014-03-05 11:13:14

标签: php api laravel rest-client

我被Auth::attempt困在api。

UserController.php

$credentials = ['user_email' => $data['email'],'user_password' => md5($data['password'])];
if (Auth::attempt($credentials)) {
    return Redirect::route("user/profile");
}

user.php的

<?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;
    }

}

auth.php

return array(
'driver' => 'eloquent',
'model' => 'User',
'table' => '',
'reminder' => array(
    'email' => 'emails.auth.reminder',
    'table' => 'password_reminders',
    'expire' => 60,
    ),
);

错误消息

它返回ErrorException,因为我使用RESTClient来测试api我无法轻易调试错误。有人可以帮助我。

1 个答案:

答案 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,据我所知,在密码方面我知道更好的哈希算法