Skip to content

Commit

Permalink
Use TOTP service in login
Browse files Browse the repository at this point in the history
  • Loading branch information
usp-npe committed Apr 21, 2022
1 parent 285d378 commit 9a43330
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use App\Events\UserSelfRegistered;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Services\TOTPService;
use Exception;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Validator;
use OTPHP\TOTP;
use Socialite;

class LoginController extends Controller
Expand Down Expand Up @@ -87,7 +87,7 @@ public function showLoginForm()
*
* @throws \Illuminate\Validation\ValidationException
*/
public function login(Request $request)
public function login(Request $request, TOTPService $totp)
{
$this->validateLogin($request);

Expand All @@ -108,9 +108,8 @@ public function login(Request $request)
$validator = Validator::make($request->all(), [
'code' => 'required|numeric',
])
->after(function ($validator) use ($user, $request) {
$otp = TOTP::create($user->tfa_secret);
if (! $otp->verify($request->code, null, 1)) {
->after(function ($validator) use ($user, $request, $totp) {
if (!$totp->verify($user->tfa_secret, $request->code, null, 1)) {
$validator->errors()->add('code', __('Invalid code, please repeat.'));
}
});
Expand Down

0 comments on commit 9a43330

Please sign in to comment.