am trying to work on a project in laravel 4.2 but now, i would like to limit on the number of login attempts for users.most solutions are laravel 5 and am not familiar with 5. so anyone with an idea please i need your help. thank you.
$data = Input::all();
$rules = array(
'username' =>'required|',
'password' => 'required|min:6'
);
$validator = Validator::make($data, $rules);
if($validator->passes())
{
$user = array(
'username'=> Input::get('username'),
'password' => Input::get('password'),
'active'=>1,
);
if(Auth::attempt($user))
{
if((Auth::user()->isBuyer()))
{
return Redirect::route('customer')->with(['success' => 'Welcome <strong style="color:black">'.Auth::user()->name .'</strong>']);
}
elseif((Auth::user()->isSeller()))
{
return Redirect::route('seller')->with(['success' => 'Welcome <strong style="color:black">'.Auth::user()->name .'</strong>']);
}
else
{
return Redirect::route('dashboard')->with(['success' => 'Welcome <strong style="color:black">'.Auth::user()->name.' </strong>']);
}
}
return Redirect::back()
->with(array(
'error' => 'Your email and password combination is invalid or Verify your email first'
));
}
return Redirect::back()
->withInput()
->withErrors($validator);
}
that is my controller function for logging in
There is so many way to do that. But below are common and i usually do.
1.) Add column "attempt" to users table and increment each time the user is failed to log on. Reset the column back to 0 if the user is successfully logged in.
2.) Create session "attempt" and increment each time the user is failed to log on. Reset the session back to 0 if the user is successfully logged in. You can also block user to log in for x number of minutes.
But i prefer the option 1 so the user cannot log in even if he uses different browser.