Skip to content

Commit

Permalink
Factor out cookie storing to separate methods
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Jun 12, 2014
1 parent 234cfbf commit 92a10d0
Showing 1 changed file with 42 additions and 17 deletions.
59 changes: 42 additions & 17 deletions libraries/plugins/auth/AuthenticationCookie.class.php
Expand Up @@ -561,25 +561,10 @@ public function authSetUser()

// Name and password cookies need to be refreshed each time
// Duration = one month for username
$GLOBALS['PMA_Config']->setCookie(
'pmaUser-' . $GLOBALS['server'],
$this->cookieEncrypt(
$cfg['Server']['user'],
$this->_getEncryptionSecret()
)
);
$this->storeUsernameCookie($cfg['Server']['user']);

// Duration = as configured
$GLOBALS['PMA_Config']->setCookie(
'pmaPass-' . $GLOBALS['server'],
$this->cookieEncrypt(
! empty($cfg['Server']['password'])
? $cfg['Server']['password'] : "\xff(blank)",
$this->_getSessionEncryptionSecret()
),
null,
$GLOBALS['cfg']['LoginCookieStore']
);
$this->storePasswordCookie($cfg['Server']['password']);

// Set server cookies if required (once per session) and, in this case,
// force reload to ensure the client accepts cookies
Expand Down Expand Up @@ -636,7 +621,47 @@ public function authSetUser()
} // end if

return true;
}

/**
* Stores username in a cookie.
*
* @param string $username User name
*
* @return void
*/
public function storeUsernameCookie($username)
{
// Name and password cookies need to be refreshed each time
// Duration = one month for username
$GLOBALS['PMA_Config']->setCookie(
'pmaUser-' . $GLOBALS['server'],
$this->cookieEncrypt(
$username,
$this->_getEncryptionSecret()
)
);
}

/**
* Stores password in a cookie.
*
* @param string $password Password
*
* @return void
*/
public function storePasswordCookie($password)
{
// Duration = as configured
$GLOBALS['PMA_Config']->setCookie(
'pmaPass-' . $GLOBALS['server'],
$this->cookieEncrypt(
! empty($password) ? $password : "\xff(blank)",
$this->_getSessionEncryptionSecret()
),
null,
$GLOBALS['cfg']['LoginCookieStore']
);
}

/**
Expand Down

0 comments on commit 92a10d0

Please sign in to comment.