diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-10-31 15:38:50 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-10-31 15:38:50 +0000 |
commit | f93bc85184077506c555e444c55abbeb1976f03e (patch) | |
tree | be532d1919f1d0044a15caef8ffce2a3475609db /perllib/FixMyStreet/App.pm | |
parent | c76880f3ce225df63cb8f712982177b8ca5b2d0e (diff) | |
parent | 3d593bc68d65015a50f8f4b1a6d9f818d8678226 (diff) |
Merge branch '2fa-improvements'
Diffstat (limited to 'perllib/FixMyStreet/App.pm')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 27a5a4580..1173523bc 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -13,6 +13,7 @@ use FixMyStreet::Email::Sender; use FixMyStreet::PhotoStorage; use Utils; +use Auth::GoogleAuth; use Path::Tiny 'path'; use Try::Tiny; use Text::CSV; @@ -516,6 +517,23 @@ sub set_param { $c->req->params->{$param} = $value; } +=head2 check_2fa + +Given a user's secret, verifies a submitted code. + +=cut + +sub check_2fa { + my ($c, $secret32) = @_; + + if (my $code = $c->get_param('2fa_code')) { + my $auth = Auth::GoogleAuth->new; + return 1 if $auth->verify($code, 2, $secret32); + $c->stash->{incorrect_code} = 1; + } + return 0; +} + =head1 SEE ALSO L<FixMyStreet::App::Controller::Root>, L<Catalyst> |