PHP code example of jslmariano / basic-authentication-otp
1. Go to this page and download the library: Download jslmariano/basic-authentication-otp library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jslmariano / basic-authentication-otp example snippets
namespace App\Http\Controllers\Auth;
use Jslmariano\AuthenticationOtp\Services\Auth\OTP as OTPService;
class AuthController extends Controller
{
...
public function login(Request $request)
{
...
/**
* OTP FEATURE
*/
$otp_service = new OTPService();
if ($otp_service->resolveUser($credentials)->isUserNeedsOTP($request)) {
$otp_service->processOtp($request);
return $otp_service->getResponse();
}
/**
* OTP FEATURE END
* This is to avoid generation of token
*/
...
/* Should be before this code below */
/* Code below may vary depending on how you authenticate your users */
if (!$token = JWTAuth::attempt($credentials)) {
return response([
'status' => 'error',
'error' => 'invalid.credentials',
'msg' => 'Invalid Credentials.',
], 400);
}
Auth::loginUsingId(Auth::User()->id);
...
}