erwin32 / ldap
一个简单的库,用于通过LDAP进行认证,并具有一些额外功能
1.3
2018-01-26 13:25 UTC
This package is not auto-updated.
Last update: 2024-09-28 14:23:14 UTC
README
一个用于非常简单的LDAP认证的类,检查用户是否存在以及用户是否在给定的组中。
用法
$ composer require erwin32/ldap
初始化示例
// Active Directory server $ldap_host = "123.123.123.123";//IP adress or url // Active Directory DN $ldap_dn = 'DC=domain,DC=com';//domain in this example is used "domain.com" // Active Directory user group $ldap_user_group = "Group Name"; // Active Directory manager group $ldap_manager_group = "Admins"; // Domain, for purposes of constructing $user $ldap_usr_dom = "@domain.com"; //class inicialization $ldap=new \LDAP\auth($ldap_host, $ldap_dn, $ldap_user_group, $ldap_manager_group, $ldap_usr_dom);
用于认证的使用方法(期望已初始化的类在$ldap中)
第一个参数是用户名,第二个是密码
try { $ldap->authenticate($user, $pass); } catch (Exception $exc) { $msg=$exc->getMessage(); $code=$exc->getCode(); //this is how we can determine if user dont have corect group but exist on LDAP if($ldap::ERROR_WRONG_USER_GROUP==$code){ //custom handling } }
缩略图图片检索示例
try { $ldap->userInit($user, $pass); //we can display it like this echo '<img src="'.$ldap->getLDAPimg().'">'; } catch (Exception $exc) { $msg=$exc->getMessage(); $code=$exc->getCode(); //react to problems }
异常错误代码
$ldap::ERROR_WRONG_USER_GROUP $ldap::ERROR_CANT_AUTH $ldap::ERROR_CANT_SEARCH $ldap::ERROR_IMG_DECODE