Move getting time into the scope where it is used

pull/3630/head
Isaac Connor 2022-11-02 10:07:01 -04:00
parent 6d2b2ae525
commit d00536915e
1 changed files with 4 additions and 4 deletions

View File

@ -231,9 +231,6 @@ function calculateAuthHash($remoteAddr='') {
function generateAuthHash($useRemoteAddr, $force=false) {
global $user;
if (ZM_OPT_USE_AUTH and (ZM_AUTH_RELAY == 'hashed') and isset($user['Username']) and isset($user['Password'])) {
$time = time();
# We use 1800 so that we regenerate the hash at half the TTL
$mintime = $time - (ZM_AUTH_HASH_TTL * 1800);
if (!isset($_SESSION)) {
# Appending the remoteAddr prevents us from using an auth hash generated for a different ip
@ -241,9 +238,12 @@ function generateAuthHash($useRemoteAddr, $force=false) {
$auth = calculateAuthHash();
return $auth;
} else {
$time = time();
# We use 1800 so that we regenerate the hash at half the TTL
$mintime = $time - (ZM_AUTH_HASH_TTL * 1800);
# Appending the remoteAddr prevents us from using an auth hash generated for a different ip
if ($force or ( !isset($_SESSION['AuthHash'.$_SESSION['remoteAddr']]) ) or ( $_SESSION['AuthHashGeneratedAt'] < $mintime )) {
$auth = calculateAuthHash($useRemoteAddr?$_SESSION['remoteAddr']:'');
$auth = calculateAuthHash($useRemoteAddr ? $_SESSION['remoteAddr'] : '');
# Don't both regenerating Auth Hash if an hour hasn't gone by yet
$_SESSION['AuthHash'.$_SESSION['remoteAddr']] = $auth;
$_SESSION['AuthHashGeneratedAt'] = $time;