Reputation: 35
I am stuck with Auth::attempt
for an 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,
),
);
Its returning ErrorException since I am using RESTClient to test the api I can't debug easily the errors. Can somebody please help me.
Upvotes: 0
Views: 2138
Reputation: 1521
Laravel provided
Hash::make()
to make your life easier,
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');
}
}
you don't need to use MD5, Laravel uses bcrypt, which as far as i know a better hash algorithm when it comes to passwords
Upvotes: 1