aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/LoginManager.php
diff options
context:
space:
mode:
authorVirtualTam <virtualtam@flibidi.net>2018-04-18 23:09:45 +0200
committerVirtualTam <virtualtam@flibidi.net>2018-06-02 16:46:06 +0200
commit847420847455c1339f3302b1b67568ee0f382a11 (patch)
treeb84194d0f048d12357479c57d16eff40263e8a03 /application/LoginManager.php
parentc7721487b2459e6760cae9d6292b7d39c306d3d6 (diff)
downloadShaarli-847420847455c1339f3302b1b67568ee0f382a11.tar.gz
Shaarli-847420847455c1339f3302b1b67568ee0f382a11.tar.zst
Shaarli-847420847455c1339f3302b1b67568ee0f382a11.zip
Pass the client IP ID to LoginManager
Signed-off-by: VirtualTam <virtualtam@flibidi.net>
Diffstat (limited to 'application/LoginManager.php')
-rw-r--r--application/LoginManager.php28
1 files changed, 13 insertions, 15 deletions
diff --git a/application/LoginManager.php b/application/LoginManager.php
index 347fb3b9..5ce836fa 100644
--- a/application/LoginManager.php
+++ b/application/LoginManager.php
@@ -48,15 +48,15 @@ class LoginManager
48 /** 48 /**
49 * Check user session state and validity (expiration) 49 * Check user session state and validity (expiration)
50 * 50 *
51 * @param array $server The $_SERVER array 51 * @param array $session The $_SESSION array (reference)
52 * @param array $session The $_SESSION array (reference) 52 * @param array $cookie The $_COOKIE array
53 * @param array $cookie The $_COOKIE array 53 * @param string $webPath Path on the server in which the cookie will be available on
54 * @param string $webPath Path on the server in which the cookie will be available on 54 * @param string $clientIpId Client IP address identifier
55 * @param string $token Session token 55 * @param string $token Session token
56 * 56 *
57 * @return bool true if the user session is valid, false otherwise 57 * @return bool true if the user session is valid, false otherwise
58 */ 58 */
59 public function checkLoginState($server, & $session, $cookie, $webPath, $token) 59 public function checkLoginState(& $session, $cookie, $webPath, $clientIpId, $token)
60 { 60 {
61 if (! $this->configManager->exists('credentials.login')) { 61 if (! $this->configManager->exists('credentials.login')) {
62 // Shaarli is not configured yet 62 // Shaarli is not configured yet
@@ -64,8 +64,6 @@ class LoginManager
64 return; 64 return;
65 } 65 }
66 66
67 $clientIpId = client_ip_id($server);
68
69 if (isset($cookie[SessionManager::$LOGGED_IN_COOKIE]) 67 if (isset($cookie[SessionManager::$LOGGED_IN_COOKIE])
70 && $cookie[SessionManager::$LOGGED_IN_COOKIE] === $token 68 && $cookie[SessionManager::$LOGGED_IN_COOKIE] === $token
71 ) { 69 ) {
@@ -100,13 +98,14 @@ class LoginManager
100 /** 98 /**
101 * Check user credentials are valid 99 * Check user credentials are valid
102 * 100 *
103 * @param array $server The $_SERVER array 101 * @param string $remoteIp Remote client IP address
104 * @param string $login Username 102 * @param string $clientIpId Client IP address identifier
105 * @param string $password Password 103 * @param string $login Username
104 * @param string $password Password
106 * 105 *
107 * @return bool true if the provided credentials are valid, false otherwise 106 * @return bool true if the provided credentials are valid, false otherwise
108 */ 107 */
109 public function checkCredentials($server, $login, $password) 108 public function checkCredentials($remoteIp, $clientIpId, $login, $password)
110 { 109 {
111 $hash = sha1($password . $login . $this->configManager->get('credentials.salt')); 110 $hash = sha1($password . $login . $this->configManager->get('credentials.salt'));
112 111
@@ -115,17 +114,16 @@ class LoginManager
115 ) { 114 ) {
116 logm( 115 logm(
117 $this->configManager->get('resource.log'), 116 $this->configManager->get('resource.log'),
118 $server['REMOTE_ADDR'], 117 $remoteIp,
119 'Login failed for user ' . $login 118 'Login failed for user ' . $login
120 ); 119 );
121 return false; 120 return false;
122 } 121 }
123 122
124 $clientIpId = client_ip_id($server);
125 $this->sessionManager->storeLoginInfo($clientIpId); 123 $this->sessionManager->storeLoginInfo($clientIpId);
126 logm( 124 logm(
127 $this->configManager->get('resource.log'), 125 $this->configManager->get('resource.log'),
128 $server['REMOTE_ADDR'], 126 $remoteIp,
129 'Login successful' 127 'Login successful'
130 ); 128 );
131 return true; 129 return true;