php - Laravel Auth::attempt( ) failing -
i working on login system using laravel 4
. can register
users when try login
using details - email , password fails every time , don't know why.
this schema
users
table in db
:
schema::create('users', function($table){ $table->increments('id'); $table->string('fname', 255); $table->string('lname', 255); $table->string('email')->unique(); $table->string('password',128); $table->string('remember_token', 100); $table->timestamps(); });
this login form
:
<form action="{{action('homecontroller@handlelogin')}}" method="post"> <div class="form-group"> <label for="email">email</label> <input type="text" class="form-control" name="email"/> </div> <div class="form-group"> <label for="password">password</label> <input type="password" class="form-control" name="password"/> </div> <input type="submit" value="login" class="btn btn-primary"/> </form>
this login action
in homecontroller
:
public function handlelogin() { $rules = array( 'email' => 'required', 'password' => 'required' ); $credentials = array( 'email' => input::get('email'), 'password' => input::get('password') ); $validator = validator::make($credentials, $rules); if($validator->passes()){ echo "validation passed"; if(auth::attempt($credentials)){ echo "logged in";die(); }else{ echo "logged failed";die(); } }else{ echo "validation failed";die(); } }
i don't understand why failing, if hard code email , password $credentials
array not login.
any appreciated it.
register code
public function handleregister(){ //validation rules $rules = array( 'fname'=>'required|alpha|min:2', 'lname'=>'required|alpha|min:2', 'email'=>'required|email|unique:users', 'password'=>'required|alpha_num|between:6,12|confirmed', 'password_confirmation'=>'required|alpha_num|between:6,12' ); //validator $validator = validator::make(input::all(), $rules); if($validator->passes()){//pass //save user db $user = new user; $user->fname = input::get('fname'); $user->lname = input::get('lname'); $user->email = input::get('email'); $user->password = hash::make(input::get('password')); $user->save(); return redirect::action('homecontroller@getlogin')->with('message', 'thanks registering!'); }else{//fail //display errors return redirect::action('homecontroller@getregister')->with('message', 'the following errors occured')->witherrors($validator)->withinput(); } }
database row
id type fname lname email password school address_1 address_2 address_3 address_4 remember_token created_at updated_at 7 \n jack coldrick jackcoldrick@yahoo.com $2y$10$nrdbkoeeyob4nliphgeb5u2qvcs2xwu/x7zicxq3my3tqwckie6a6 \n \n \n \n \n 2014-08-18 14:01:22 2014-08-18 14:01:22
try login manually
public function handlelogin() { $rules = array( 'email' => 'required', 'password' => 'required' ); $credentials = array( 'email' => input::get('email'), 'password' => input::get('password') ); $validator = validator::make($credentials, $rules); if($validator->passes()){ echo "validation passed"; $user = user::where('email', $credentials['email']) ->andwhere('password', hash::make($credentials['email'])) ->first(); if(null !== $user && auth::login($user)){ echo "logged in";die(); }else{ echo "logged failed";die(); } }else{ echo "validation failed";die(); } }
Comments
Post a Comment