"; endif; if ($debug) : echo "hq_id = " . $hq_id . ""; endif; // The session has to be set, otherwise go back to login page! if (isset($_SESSION['usr_id']) && isset($_SESSION['hq_id']) && isset($usr_id) && $usr_id != "" && is_numeric($usr_id) && $usr_id > 0 && isset($hq_id) && $hq_id != "" && is_numeric($hq_id) && $hq_id > 0) : if ($f_act == "verify") : $f_act = ""; $verificationOK = false; if ($f_2faCode != "") : $usrTotpSecret = getFieldValueFromId("user", "usr_id", $usr_id, "usr_totp_secret"); if ($usrTotpSecret != "") : $ga = new GoogleAuthenticator(); $currentCode = $ga->getCode($usrTotpSecret); if ($f_2faCode == $currentCode) : $tmpNum = rand(0,getrandmax()); $tmpSessionHash = md5($tmpNum); updateStmt("user", "usr_id", $usr_id, array("usr_totp_sessionkey", $tmpSessionHash)); $_SESSION["sessionkey_2fa"] = $tmpSessionHash; $verificationOK = true; endif; endif; endif; if ($verificationOK) : header("Location: ../admin/start.php"); else : session_destroy(); header("Location: ../admin/login.php"); if ($debug) : echo "VERIFICATION NOT OK:"; endif; if ($debug) : echo "f_2faCode = " . $f_2faCode . ""; endif; if ($debug) : echo "currentCode = " . $currentCode . ""; endif; endif; endif; else : session_destroy(); header("Location: ../admin/login.php"); endif; ?>