public static void Main(String []args) { string username="CN=aziz.alkurt,CN=Users,dc=datakent,dc=com"; /*windows server için username="aziz.alkurt@datakent.com" girilebilir*/ /*sunucunun yapılandırılmasına göre değişebilir. örneğin username= "uid=aziz.alkurt,ou=people,dc=datakent,dc=com" gibi */ string password="XXX"; string domain=""; //Kullanılıyorsa girilebilir. string server="localhost:636"; /*ip:port veya ssl kullanılmıyor ve default port kullanılıyorsa yalnızca ip girilebilir.*/ bool useSSL=true; /*SSL Kullanılıyor mu?*/ bool val= bool IsAuthenticated(server,domain, username, password, useSSL); MessageBox.Show("Kullanıcı girişi "+val ? "başarılı":"başarısız"); } private static bool IsAuthenticated(string server, string domain, string username, string password, bool useSSL) { try { LdapDirectoryIdentifier id = new LdapDirectoryIdentifier(server); LdapConnection conn = new LdapConnection(id); if (useSSL) { conn.SessionOptions.SecureSocketLayer = true; conn.SessionOptions.VerifyServerCertificate = new VerifyServerCertificateCallback((con, cer) => true); } conn.AuthType = AuthType.Basic; conn.SessionOptions.ProtocolVersion = 3; // 2 veya 3 olabillir. conn.Credential = new NetworkCredential(username, password, domain); conn.Bind(); return true; } catch { return false; } }
|