mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-29 11:43:26 +01:00
Add logic to force HOTP counter
This commit is contained in:
parent
1d06aae30d
commit
6726d85eb0
@ -98,7 +98,33 @@ public function update(Request $request, $id)
|
|||||||
try {
|
try {
|
||||||
|
|
||||||
$twofaccount = TwoFAccount::FindOrFail($id);
|
$twofaccount = TwoFAccount::FindOrFail($id);
|
||||||
$twofaccount->update($request->all());
|
|
||||||
|
if( $twofaccount->type === 'hotp' ) {
|
||||||
|
|
||||||
|
// HOTP can be desynchronized from the verification
|
||||||
|
// server so we let the user the possibility to force
|
||||||
|
// the counter.
|
||||||
|
|
||||||
|
$this->validate($request, [
|
||||||
|
'counter' => 'required|integer',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// we set an OTP object to get the its current counter
|
||||||
|
// and we update it if a new one has been submited
|
||||||
|
$otp = OTP::get($twofaccount->uri);
|
||||||
|
|
||||||
|
if( $otp->getCounter() !== $request->counter ) {
|
||||||
|
$otp->setParameter( 'counter', $request->counter );
|
||||||
|
$twofaccount->uri = $otp->getProvisioningUri();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$twofaccount->update([
|
||||||
|
'service' => $request->service,
|
||||||
|
'account' => $request->account,
|
||||||
|
'icon' => $request->icon,
|
||||||
|
'uri' => $twofaccount->uri,
|
||||||
|
]);
|
||||||
|
|
||||||
return response()->json($twofaccount, 200);
|
return response()->json($twofaccount, 200);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user