C # uses Domino's LDAP service to authenticate users

Source: Internet
Author: User
Tags ldap ldap search filter

First, Domino's LDAP service is configured to not be anonymous, otherwise it doesn't make sense.

Security, Internet Authentication is set to: More name transformations, lower security.

In this case, the username can be used in Domino's personal documents: Name + space + surname, abbreviation, email address

You can not set this if you do not need it.

Password is: internet password

By default, Domino's LDAP attribute has no UID (abbreviated) and needs to be added by itself.

Principle: Use the input username password to execute an LDAP query, if no exception is thrown, the user name password is correct.

1using System.DirectoryServices;


2using System.Configuration;


3using System.Text;


4


5 public class Ldaphelper


6 {


7


8 private string dominoserver;


9/**////<summary>


///Domino server address


///</summary>


public string Dominoserver


13 {


get {return dominoserver;}


set {dominoserver = value;}


16}


private String Ldapserver;


/**////<summary>


///LDAP server address


///</summary>


public string Ldapserver


22 {


{return ldapserver;}


set {ldapserver = value;}


25}


26


private String UserName;


/**////<summary>


29///User name


///</summary>


public string UserName


32 {


to {return userName;}


set {userName = value;}


35}


36


Notoginseng private string password;


/**////<summary>


39///Password


///</summary>


-public string Password


42 {


/get {return password;}


set {password = value;}


45}


/**////<summary>


47///Instantiation


///</summary>


///<param name= "UserName" > Username </param>


///<param name= "password" > password </param>


Wuyi Public Ldaphelper (String userName, string password)


52 {


Try


54 {


//this. Ldapserver = configurationmanager.appsettings["Ldapserver"]. ToString ();


56


//this. Dominoserver = configurationmanager.appsettings["Dominoserver"]. ToString ();


58


this. Ldapserver = "192.176.0.46";


60


this. Dominoserver= "192.176.0.46"


62


. UserName = UserName;


. Password = Password;


65}


The Catch


67 {


throw;


69}


70}


71


/**////<summary>


73///Verify that the user name password is correct through the Domino LDAP Service


///</summary>


///<param name= "userName" > User name </param>


///<param name= "password" > password </param>


///<returns></returns>


public bool Verifyuser ()


79 {


Try


81 {


DirectorySearcher searcher = Preparesearcher ();


83


84///Execute the following method without throwing an exception stating that the username password is correct


SearchResult rs = searcher. FindOne ();


86


return true;


88}



Catch

90 {


return false;


92}


93}


94


/**////<summary>


///Prepare DirectorySearcher


///</summary>


///<returns>DirectorySearcher</returns>


private DirectorySearcher preparesearcher ()


100 {


101


102 DirectoryEntry root = new DirectoryEntry (this. Ldapserver, this. UserName, this. Password, Authenticationtypes.none);


DirectorySearcher searcher = new DirectorySearcher (root);


104


//ldap Search filter conditions, CN for the user name, UID for the user abbreviation


106


Searcher. Filter = "(& (Objectclass=dominoperson) ( Cn= "+ this. UserName +


108


109 ") (uid=" + this. UserName + ") (mail=" + this. UserName + "))";


110


111


112//searcher. Filter = "(& (Objectclass=dominoperson) (cn=) + this. UserName + ")";


113 return searcher;


114


115}


116}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.