Novell.Directory.Ldap.LdapConnection.Compare C# (CSharp) 메소드

Compare() 공개 메소드

Asynchronously compares an attribute value with one in the directory, using the specified queue. Please note that a successful completion of this command results in one of two status codes: LdapException.COMPARE_TRUE if the entry has the value, and LdapException.COMPARE_FALSE if the entry does not have the value or the attribute.
LdapException A general exception which includes an error /// message and an Ldap error code. /// ///
public Compare ( System dn, LdapAttribute attr, LdapResponseQueue queue ) : LdapResponseQueue
dn System The distinguished name of the entry containing an /// attribute to compare. /// ///
attr LdapAttribute An attribute to compare. /// ///
queue LdapResponseQueue The queue for messages returned from a server in /// response to this request. If it is null, a /// queue object is created internally. /// ///
리턴 LdapResponseQueue
        public virtual LdapResponseQueue Compare(System.String dn, LdapAttribute attr, LdapResponseQueue queue)
        {
            return Compare(dn, attr, queue, defSearchCons);
        }

Same methods

LdapConnection::Compare ( System dn, LdapAttribute attr, LdapResponseQueue queue, LdapConstraints cons ) : LdapResponseQueue
LdapConnection::Compare ( System dn, LdapAttribute attr ) : bool
LdapConnection::Compare ( System dn, LdapAttribute attr, LdapConstraints cons ) : bool

Usage Example

예제 #1
0
    public static void Main(System.String[] args)
    {
        if (args.Length != 5)
        {
            System.Console.Out.WriteLine("Usage:   mono VerifyPassword <host name>" + " <login dn> <password> <object dn>\n" + "         <test password>");
            System.Console.Out.WriteLine("Example: mono VerifyPassword Acme.com " + "\"cn=Admin,o=Acme\" secret\n" + "         \"cn=JSmith,ou=Sales,o=Acme\" testPassword");
            System.Environment.Exit(0);
        }

        int ldapPort = LdapConnection.DEFAULT_PORT;
        int ldapVersion = LdapConnection.Ldap_V3;
        System.String ldapHost = args[0];
        System.String loginDN = args[1];
        System.String password = args[2];
        System.String objectDN = args[3];
        System.String testPassword = args[4];
        LdapConnection conn = new LdapConnection();

        try
        {
            // connect to the server
            conn.Connect(ldapHost, ldapPort);

            // authenticate to the server
            conn.Bind(ldapVersion, 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 (LdapException e)
        {
            if (e.ResultCode == LdapException.NO_SUCH_OBJECT)
            {
                System.Console.Error.WriteLine("Error: No such entry");
            }
            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);
    }
All Usage Examples Of Novell.Directory.Ldap.LdapConnection::Compare