X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/459706908311101286dadb87a2f12afbf4192bbb..refs/pull/3391/head:/app/Auth/Access/Mfa/BackupCodeService.php diff --git a/app/Auth/Access/Mfa/BackupCodeService.php b/app/Auth/Access/Mfa/BackupCodeService.php index 6fbbf64b5..d58d28ae1 100644 --- a/app/Auth/Access/Mfa/BackupCodeService.php +++ b/app/Auth/Access/Mfa/BackupCodeService.php @@ -29,25 +29,21 @@ class BackupCodeService { $cleanCode = $this->cleanInputCode($code); $codes = json_decode($codeSet); + return in_array($cleanCode, $codes); } /** * Remove the given input code from the given available options. - * Will return null if no codes remain otherwise will be a JSON string to contain - * the codes. + * Will return a JSON string containing the codes. */ - public function removeInputCodeFromSet(string $code, string $codeSet): ?string + public function removeInputCodeFromSet(string $code, string $codeSet): string { $cleanCode = $this->cleanInputCode($code); $codes = json_decode($codeSet); $pos = array_search($cleanCode, $codes, true); array_splice($codes, $pos, 1); - if (count($codes) === 0) { - return null; - } - return json_encode($codes); } @@ -63,4 +59,4 @@ class BackupCodeService { return strtolower(str_replace(' ', '-', trim($code))); } -} \ No newline at end of file +}