php - Laravel authentication with MongoDB -
i'm trying make authentication laravel , mongodb.
the problem in controller. code not make authentication :
if(!input::exists('username') or !input::exists('password')) { app::abort(403, 'forbidden request'); } $credentials = array( 'username' => input::get('username', null), 'password' => input::get('password', null), ); if(auth::validate($credentials)) { return 'success'; } else { return 'failed'; }
but 1 works fine:
if(!input::exists('username') or !input::exists('password')) { app::abort(403, 'forbidden request'); } $credentials = array( 'username' => input::get('username', null), 'password' => input::get('password', null), ); $users = user::all(); $found = false; foreach($users $user) { if($user->username == $credentials['username'] , hash::check($credentials['password'], $user->password)) { $found = true; break; } } if($found) { return 'success'; } else { return 'failed'; }
both controllers given same username
, password
. first 1 prints failed
, second 1 gives true results.
the problem using auth::validate
checks if credentials correct, not log user in. need use auth::attempt
complete login. see docs here http://laravel.com/docs/security#authenticating-users .
Comments
Post a Comment