mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-03-30 18:26:14 +02:00
Check OTP validity before creation
This commit is contained in:
parent
24e643ff87
commit
ffaef86909
@ -37,6 +37,8 @@ public function store(Request $request)
|
|||||||
'uri' => 'required|regex:/^otpauth:\/\/[h,t]otp\//i',
|
'uri' => 'required|regex:/^otpauth:\/\/[h,t]otp\//i',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->validateOTP($request->uri);
|
||||||
|
|
||||||
$twofaccount = TwoFAccount::create([
|
$twofaccount = TwoFAccount::create([
|
||||||
'service' => $request->service,
|
'service' => $request->service,
|
||||||
'account' => $request->account,
|
'account' => $request->account,
|
||||||
@ -140,4 +142,27 @@ public function destroy($id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if the provided uri is a valid OTP uri
|
||||||
|
*
|
||||||
|
* @param \App\TwoFAccount $twofaccount
|
||||||
|
* @return \Illuminate\Http\Response
|
||||||
|
*/
|
||||||
|
private function validateOTP(String $uri) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
$otp = \OTPHP\Factory::loadFromProvisioningUri($uri);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (\Assert\AssertionFailedException $exception) {
|
||||||
|
$error = \Illuminate\Validation\ValidationException::withMessages([
|
||||||
|
'qrcode' => __('errors.response.no_valid_totp')
|
||||||
|
]);
|
||||||
|
|
||||||
|
throw $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user