yii2中的ldap登录
Ldap login in yii2
我想在yii2中进行LDAP登录
如何操作?
这是我在 LoginForm.php
中的功能。
public function authenticate($attribute, $params) {
if (!$this->hasErrors()) {
// var_dump($_POST); die;
define('DOMAIN_FQDN', 'abc.com');
define('LDAP_SERVER', '192.*.*.*');
$ldap = ldap_connect(DOMAIN_FQDN);
// echo $_POST['LoginForm']['username'];
if ($bind = ldap_bind($ldap, $_POST['LoginForm']['username'], $_POST['LoginForm']['password'])) {
echo "success";
die;
}
else{
echo "error";
die;
}
我建议在实施您自己的解决方案之前查看现有解决方案。
查看此图书馆 - Adldap2。
这里是一个验证的例子:
try {
if ($provider->auth()->attempt($username, $password)) {
// Credentials were correct.
} else {
// Credentials were incorrect.
}
} catch (\Adldap\Exceptions\Auth\UsernameRequiredException $e) {
// The user didn't supply a username.
} catch (\Adldap\Exceptions\Auth\PasswordRequiredException $e) {
// The user didn't supply a password.
}
可以在 official docs. Info about configuring is available here 的 README 中找到更多信息。
关于您最近的错误,消息很清楚 - 请检查您提供的凭据是否正确。
我想在yii2中进行LDAP登录
如何操作?
这是我在 LoginForm.php
中的功能。
public function authenticate($attribute, $params) {
if (!$this->hasErrors()) {
// var_dump($_POST); die;
define('DOMAIN_FQDN', 'abc.com');
define('LDAP_SERVER', '192.*.*.*');
$ldap = ldap_connect(DOMAIN_FQDN);
// echo $_POST['LoginForm']['username'];
if ($bind = ldap_bind($ldap, $_POST['LoginForm']['username'], $_POST['LoginForm']['password'])) {
echo "success";
die;
}
else{
echo "error";
die;
}
我建议在实施您自己的解决方案之前查看现有解决方案。
查看此图书馆 - Adldap2。
这里是一个验证的例子:
try {
if ($provider->auth()->attempt($username, $password)) {
// Credentials were correct.
} else {
// Credentials were incorrect.
}
} catch (\Adldap\Exceptions\Auth\UsernameRequiredException $e) {
// The user didn't supply a username.
} catch (\Adldap\Exceptions\Auth\PasswordRequiredException $e) {
// The user didn't supply a password.
}
可以在 official docs. Info about configuring is available here 的 README 中找到更多信息。
关于您最近的错误,消息很清楚 - 请检查您提供的凭据是否正确。