C# 验证密码Mono+;IPA(LDAP)和#x2B;莱尔
我需要在LDAP(IPA内部)中验证用户/密码。这是来自Novell的示例,但不起作用C# 验证密码Mono+;IPA(LDAP)和#x2B;莱尔,c#,mono,ldap,rhel,C#,Mono,Ldap,Rhel,我需要在LDAP(IPA内部)中验证用户/密码。这是来自Novell的示例,但不起作用 System.String ldapHost = "ipa-server.ipadev.local"; System.String loginDN = "uid=tom,cn=users,cn=compat,dc=ipadev,dc=local"; System.String password = "12345678"; System.S
System.String ldapHost = "ipa-server.ipadev.local";
System.String loginDN = "uid=tom,cn=users,cn=compat,dc=ipadev,dc=local";
System.String password = "12345678";
System.String objectDN = "cn=tim,cn=groups,cn=accounts,dc=ipadev,dc=local";
System.String testPassword = "12345678";
LdapConnection conn = new LdapConnection();
conn.SecureSocketLayer = true;
conn.UserDefinedServerCertValidationDelegate += delegate {
return true;
};
try
{
conn.Connect(ldapHost, LdapConnection.DEFAULT_SSL_PORT);
conn.Bind(loginDN, password);
LdapAttribute attr = new LdapAttribute("userPassword", testPassword);
bool correct = conn.Compare(objectDN, attr);
System.Console.Out.WriteLine(correct ? "The password is correct." : "The password is incorrect.\n");
// disconnect with the server
conn.Disconnect();
}
catch (LdapReferralException ex)
{
System.Console.Error.WriteLine ("Error: Referrals exception - " + ex.ToString());
System.Console.Error.WriteLine ("Referrals: " + ex.getReferrals ());
}
catch (LdapException e)
{
if (e.ResultCode == LdapException.NO_SUCH_OBJECT)
{
System.Console.Error.WriteLine("Error: No such entry - " + e.ToString());
}
else if (e.ResultCode == LdapException.NO_SUCH_ATTRIBUTE)
{
System.Console.Error.WriteLine("Error: No such attribute");
}
else
{
System.Console.Error.WriteLine("Error: " + e.ToString());
}
}
catch (System.IO.IOException e)
{
System.Console.Out.WriteLine("Error: " + e.ToString());
}
System.Environment.Exit(0);
如果我使用空密码-绑定将成功,但conn.Compare
给出一个错误-错误:LdapException:(50)访问权限不足
如果我使用普通密码(12345678),我会在绑定内得到-错误“LdapReferralException:(10)reference”
还有一个问题-在loginDn内部,我是否应该使用完整路径,如“uid=tom,cn=users,cn=compat,dc=ipadev,dc=local”,但用户只拥有登录名,如何创建此完整路径?在LDAP中不是这样做的。想法是以该用户的身份使用该密码进行连接,并查看是否成功。您的意思是以“tim”(tom,没关系)和他的密码进行连接(绑定)?我试图这样做,但总是有一个错误-“LdapException:(32)没有这样的对象”。如果我不知道完整路径“uid=tom,cn=users,cn=compat,dc=ipadev,dc=local”,只知道uid和dc怎么办?如果我输入了不正确的密码,所有绑定都会成功