3131require_once '../../lib/config.inc.php ' ;
3232require_once '../../lib/app.inc.php ' ;
3333
34- //* Check if we have an active users ession
34+ // Check if we have an active users ession.
3535if ($ _SESSION ['s ' ]['user ' ]['active ' ] == 1 ) {
3636 header ('Location: /index.php ' );
3737 die ();
3838}
3939
40- //* If we don't have a 2fa session go back to login page
40+ // If we don't have a 2fa session go back to login page.
4141if (!isset ($ _SESSION ['otp ' ])) {
4242 header ('Location: index.php ' );
4343 die ();
4444}
4545
46- //* Variables and settings
46+ // Variables and settings.
4747$ error = '' ;
4848$ msg = '' ;
4949$ max_session_code_retry = 3 ;
5050$ max_global_code_retry = 10 ;
5151$ otp_recovery_code_length = 32 ;
5252
53- //* CSRF Check if we got POST data
53+ // CSRF Check if we got POST data.
5454if (count ($ _POST ) >= 1 ) {
5555 $ app ->auth ->csrf_token_check ();
5656}
@@ -73,7 +73,7 @@ function finish_2fa_success($msg = '') {
7373 die ();
7474}
7575
76- //* Handle recovery code
76+ // Handle recovery code
7777if (isset ($ _POST ['code ' ]) && strlen ($ _POST ['code ' ]) == $ otp_recovery_code_length ) {
7878 //* TODO Recovery code handling
7979
@@ -93,7 +93,7 @@ function finish_2fa_success($msg = '') {
9393}
9494
9595
96- //* Begin 2fa via Email
96+ // Begin 2fa via Email.
9797if ($ _SESSION ['otp ' ]['type ' ] == 'email ' ) {
9898
9999 //* Email 2fa handler settings
@@ -103,7 +103,6 @@ function finish_2fa_success($msg = '') {
103103
104104 if (isset ($ _POST ['code ' ]) && strlen ($ _POST ['code ' ]) == $ code_length && isset ($ _SESSION ['otp ' ]['code_hash ' ])) {
105105
106-
107106 $ user = $ app ->db ->queryOneRecord ('SELECT otp_attempts FROM sys_user WHERE userid = ? ' ,$ _SESSION ['s_pending ' ]['user ' ]['userid ' ]);
108107
109108 //* Check if we reached limits
@@ -127,17 +126,17 @@ function finish_2fa_success($msg = '') {
127126 }
128127 }
129128
130- //* Send code via email
129+ // Send code via email.
131130 if (!isset ($ _SESSION ['otp ' ]['sent ' ]) || $ _GET ['action ' ] == 'resend ' ) {
132131 // Generate new code
133132 $ new_otp_code = random_int (100000 , 999999 );
134133 $ _SESSION ['otp ' ]['code_hash ' ] = password_hash ($ new_otp_code , PASSWORD_DEFAULT );
135134 //$_SESSION['otp']['code_debug'] = $new_otp_code; # for DEBUG only.
136135 $ _SESSION ['otp ' ]['starttime ' ] = time ();
137136
138- //* Ensure that code is not sent too often
137+ // Ensure that code is not sent too often
139138 if (isset ($ _SESSION ['otp ' ]['sent ' ]) && $ _SESSION ['otp ' ]['sent ' ] > $ max_code_resend ) {
140- $ app ->error ('Code resend limit reached ' ,'index.php ' );
139+ $ app ->error ('Code resend limit reached ' , 'index.php ' );
141140 }
142141
143142 $ app ->uses ('functions ' );
@@ -158,7 +157,7 @@ function finish_2fa_success($msg = '') {
158157 $ app ->ispcmail ->finish ();
159158
160159
161- //* increase sent counter
160+ // Increase sent counter.
162161 if (!isset ($ _SESSION ['otp ' ]['sent ' ])) {
163162 $ _SESSION ['otp ' ]['sent ' ] = 1 ;
164163 } else {
@@ -168,12 +167,11 @@ function finish_2fa_success($msg = '') {
168167
169168 }
170169
171- //* Show form to enter email code
170+ // Show form to enter email code
172171 // ... below
173172
174173} else {
175- //* unsupported 2fa type
176- $ app ->error ('Code resend limit reached ' ,'index.php ' );
174+ $ app ->error ('Otp method unknown ' , 'index.php ' );
177175}
178176
179177
@@ -190,13 +188,13 @@ function finish_2fa_success($msg = '') {
190188 $ app ->tpl ->setVar ('token_sent_message ' , $ token_sent_message );
191189}
192190
193- //* Load templating system and lang file
191+ // Load templating system and lang file.
194192$ app ->uses ('tpl ' );
195193$ app ->tpl ->newTemplate ('main_login.tpl.htm ' );
196194$ app ->tpl ->setInclude ('content_tpl ' , 'templates/otp.htm ' );
197195
198196
199- //* SET csrf token
197+ // SET csrf token.
200198$ csrf_token = $ app ->auth ->csrf_token_get ('otp ' );
201199$ app ->tpl ->setVar ('_csrf_id ' ,$ csrf_token ['csrf_id ' ]);
202200$ app ->tpl ->setVar ('_csrf_key ' ,$ csrf_token ['csrf_key ' ]);
0 commit comments