Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Can use backup codes to login.
James Colee41211bed7ae
diff --git a/app/Http/Controllers/Auth/TwoFactorController.php b/app/Http/Controllers/Auth/TwoFactorController.phpindex 67934843ae..b754e4b13a 100644--- a/app/Http/Controllers/Auth/TwoFactorController.php+++ b/app/Http/Controllers/Auth/TwoFactorController.php@@ -64,6 +64,17 @@ class TwoFactorController extends Controller// otp auth success!return redirect(route('home'));}++ // could be user has a backup code.+ if ($this->isBackupCode($mfaCode)) {+ $this->removeFromBackupCodes($mfaCode);+ $authenticator->login();++ session()->flash('info', trans('firefly.mfa_backup_code'));++ return redirect(route('home'));+ }+session()->flash('error', trans('firefly.wrong_mfa_code'));return redirect(route('home'));@@ -213,4 +224,33 @@ class TwoFactorController extends Controllerreturn false;}++ /**+ * Checks if code is in users backup codes.+ *+ * @param string $mfaCode+ *+ * @return bool+ */+ private function isBackupCode(string $mfaCode): bool+ {+ $list = Preferences::get('mfa_recovery', [])->data;+ if (in_array($mfaCode, $list, true)) {+ return true;+ }++ return false;+ }++ /**+ * Remove the used code from the list of backup codes.+ *+ * @param string $mfaCode+ */+ private function removeFromBackupCodes(string $mfaCode): void+ {+ $list = Preferences::get('mfa_recovery', [])->data;+ $newList = array_values(array_diff($list, [$mfaCode]));+ Preferences::set('mfa_recovery', $newList);+ }}diff --git a/resources/lang/en_US/firefly.php b/resources/lang/en_US/firefly.phpindex 1caf9d9862..309023aa61 100644--- a/resources/lang/en_US/firefly.php+++ b/resources/lang/en_US/firefly.php@@ -91,15 +91,16 @@ return ['two_factor_forgot_title' => 'Lost two factor authentication','two_factor_forgot' => 'I forgot my two-factor thing.','two_factor_lost_header' => 'Lost your two factor authentication?',- 'two_factor_lost_intro' => 'If you lost your backup codes as well, you have bad luck. This is not something you can fix from the web interface. You have two choices.',- 'two_factor_lost_fix_self' => 'If you run your own instance of Firefly III, check the logs in <code>storage/logs</code> for instructions, or run <code>docker logs <container_id></code> to see the instructions (refresh this page).',- 'two_factor_lost_fix_owner' => 'Otherwise, email the site owner, <a href="mailto::site_owner">:site_owner</a> and ask them to reset your two factor authentication.',- 'warning_much_data' => ':days days of data may take a while to load.',- 'registered' => 'You have registered successfully!',- 'Default asset account' => 'Default asset account',- 'no_budget_pointer' => 'You seem to have no budgets yet. You should create some on the <a href=":link">budgets</a>-page. Budgets can help you keep track of expenses.',- 'Savings account' => 'Savings account',- 'Credit card' => 'Credit card',+ 'two_factor_lost_intro' => 'If you lost your backup codes as well, you have bad luck. This is not something you can fix from the web interface. You have two choices.',+ 'two_factor_lost_fix_self' => 'If you run your own instance of Firefly III, check the logs in <code>storage/logs</code> for instructions, or run <code>docker logs <container_id></code> to see the instructions (refresh this page).',+ 'two_factor_lost_fix_owner' => 'Otherwise, email the site owner, <a href="mailto::site_owner">:site_owner</a> and ask them to reset your two factor authentication.',+ 'mfa_backup_code' => 'You have used a backup code to login to Firefly III. It can\'t be used again, so cross it from your list.',+ 'warning_much_data' => ':days days of data may take a while to load.',+ 'registered' => 'You have registered successfully!',+ 'Default asset account' => 'Default asset account',+ 'no_budget_pointer' => 'You seem to have no budgets yet. You should create some on the <a href=":link">budgets</a>-page. Budgets can help you keep track of expenses.',+ 'Savings account' => 'Savings account',+ 'Credit card' => 'Credit card','source_accounts' => 'Source account(s)','destination_accounts' => 'Destination account(s)','user_id_is' => 'Your user id is <strong>:user</strong>',diff --git a/resources/views/v1/auth/mfa.twig b/resources/views/v1/auth/mfa.twigindex 29eab9d37a..4addb40104 100644--- a/resources/views/v1/auth/mfa.twig+++ b/resources/views/v1/auth/mfa.twig@@ -18,7 +18,7 @@<input type="hidden" name="_token" value="{{ csrf_token() }}"/><div class="form-group has-feedback">- <input type="number" name="one_time_password" class="form-control" placeholder="{{ 'two_factor_code_here'|_ }}"/>+ <input type="text" name="one_time_password" class="form-control" placeholder="{{ 'two_factor_code_here'|_ }}"/></div><div class="row">