File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
lib/pause_2017/PAUSE/Web/Controller/User Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ use Auth::GoogleAuth;
55use PAUSE::Crypt;
66use Crypt::URandom qw( urandom) ;
77use Convert::Base32 qw( encode_base32) ;
8+ use Imager::QRCode qw( plot_qrcode) ;
9+ use URI;
810
911sub edit {
1012 my $c = shift ;
@@ -14,7 +16,7 @@ sub edit {
1416 my $u = $c -> active_user_record;
1517
1618 my $auth = $c -> app-> pause-> authenticator_for($u );
17- $pause -> {mfa_qrcode } = $auth -> qr_code ;
19+ $pause -> {mfa_qrcode } = _generate_qrcode( $auth ) ;
1820 if (!$u -> {mfa_secret32 }) {
1921 my $dbh = $mgr -> authen_connect;
2022 my $tbl = $PAUSE::Config -> {AUTHEN_USER_TABLE };
@@ -80,4 +82,16 @@ sub _generate_recovery_codes {
8082 @codes ;
8183}
8284
85+ # using $auth->qr_code directly is handy but insecure
86+ sub _generate_qrcode {
87+ my $auth = shift ;
88+ my $otpauth = $auth -> qr_code(undef , undef , undef , 1);
89+ my $img = plot_qrcode($otpauth , { casesensitive => 1 });
90+ $img -> write (data => \my $qr_png , type => ' png' ) or die " Failed to write image: " . $img -> errstr;
91+ my $data = URI-> new(" data:" );
92+ $data -> data($qr_png );
93+ $data -> media_type(' image/png' );
94+ $data ;
95+ }
96+
83971;
You can’t perform that action at this time.
0 commit comments