- if ($login != $this->configManager->get('credentials.login')
- || $hash != $this->configManager->get('credentials.hash')
- ) {
- logm(
- $this->configManager->get('resource.log'),
- $remoteIp,
- 'Login failed for user ' . $login
- );
- return false;
- }
+ return $login == $this->configManager->get('credentials.login')
+ && $hash == $this->configManager->get('credentials.hash');
+ }
+
+ /**
+ * Check user credentials are valid through LDAP bind
+ *
+ * @param string $remoteIp Remote client IP address
+ * @param string $clientIpId Client IP address identifier
+ * @param string $login Username
+ * @param string $password Password
+ *
+ * @return bool true if the provided credentials are valid, false otherwise
+ */
+ public function checkCredentialsFromLdap($login, $password, $connect = null, $bind = null)
+ {
+ $connect = $connect ?? function($host) {
+ $resource = ldap_connect($host);
+
+ ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3);
+
+ return $resource;
+ };
+ $bind = $bind ?? function($handle, $dn, $password) {
+ return ldap_bind($handle, $dn, $password);
+ };