Skip to content

Commit 8eaa875

Browse files
committed
Only regenerate code when sending a mail $new_otp_code is not stored unhashed
1 parent f30ba51 commit 8eaa875

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

interface/web/login/otp.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ function finish_2fa_success($msg = '') {
101101
$max_time = 600; // time in seconds until the code gets invalidated
102102
$code_length = 6;
103103

104-
if(isset($_POST['code']) && strlen($_POST['code']) == $code_length && isset($_SESSION['otp']['code'])) {
104+
if(isset($_POST['code']) && strlen($_POST['code']) == $code_length && isset($_SESSION['otp']['code_hash'])) {
105105

106-
if(strlen($_SESSION['otp']['code']) != $code_length) die(); // wrong code lenght, this should never happen
107106

108107
$user = $app->db->queryOneRecord('SELECT otp_attempts FROM sys_user WHERE userid = ?',$_SESSION['s_pending']['user']['userid']);
109108

@@ -128,16 +127,13 @@ function finish_2fa_success($msg = '') {
128127
}
129128
}
130129

131-
//* set code
132-
if(!isset($_SESSION['otp']['code']) || empty($_SESSION['otp']['code'])) {
130+
//* Send code via email
131+
if(!isset($_SESSION['otp']['sent']) || $_GET['action'] == 'resend') {
132+
// Generate new code
133133
$new_otp_code = random_int(100000, 999999);
134134
$_SESSION['otp']['code_hash'] = password_hash($new_otp_code, PASSWORD_DEFAULT);
135135
//$_SESSION['otp']['code_debug'] = $new_otp_code; # for DEBUG only.
136136
$_SESSION['otp']['starttime'] = time();
137-
}
138-
139-
//* Send code via email
140-
if(!isset($_SESSION['otp']['sent']) || $_GET['action'] == 'resend') {
141137

142138
//* Ensure that code is not sent too often
143139
if(isset($_SESSION['otp']['sent']) && $_SESSION['otp']['sent'] > $max_code_resend) {

0 commit comments

Comments
 (0)