using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls Using system.Web.ui.htmlcontrols;
Using System.directoryServices;
Namespace Test1 {///
#Region Web Form Designer Generated Code Override Protected Void OnNit (Eventargs E) {// // Codegen: This call is required for the ASP.NET Web Form Designer. // InitializeComponent (); base.onit (e);} ///
} #Endregion
private void Button1_Click (object sender, System.EventArgs e) {this.Response.Write (IsAuthenticated (this.TextBox1.Text.ToString (), this.TextBox2.Text.ToString (), this.TextBox3.Text.ToString () ));
public bool IsAuthenticated (string domain, string username, string pwd) {string domainAndUsername = domain @ "/" username; // DirectoryEntry entry = new DirectoryEntry (_path, domainAndUsername, pwd); // DirectoryEntry entry = new DirectoryEntry ( " WinNT: // ", domainAndUsername, pwd); DirectoryEntry entry = new DirectoryEntry (" LDAP: //rl.com ", domainAndUsername, pwd); // DirectoryEntry entry = new DirectoryEntry (" LDAP: //rl.com/CN = Xuhu, CN = Users, DC = RL, DC = COM "); // DirectoryEntry Entry = New DirectoryEntry (" Winnt: // Web / Administrator "," User "); //entry.invoke ("123", "A1B2C3D4_"); //entry.commitchanges();//ldap ://rl.com/cn=xuhu ,cn=users, dc=RL, dc=com
// to-do: Need to solve the password policy problem // entry.invoke ("changePassword", new object [] {"A1B2C3D4_", "A1B2C3D_4"}; // entry.commitchanges ();
// Bind to this unit ADSObject to force authentication. Object obj = entry.nativeObject; DirectorySearcher Search = New DirectorySEARCHER (ENTRY);
Search.filter = "(SamaccountName =" UserName ")"; search.propertiestoload.Add ("cn"); searchResult result = search.findone ();
// DirectoryEntry de = new direct.path); ////De.invoke ("changePassword ", new object [] {" A1B2C3D4_ "," In4npq0umo2i "}; // de.invoke (" ChangePassword ", New Object [] {"A1B2C3D4_", "A1B2C3D4 _"}; // de.commitchanges (); /////entry.invoke ("a1b2c3d4_", "a1b2c3d5_ "); //entry.commitchanges (); //entry.commitchanges ();
If (null == result) {return false;} // update the new path of the user in the directory // _ path = result.path; // _ filterrattribute = (String) Result.properties ["cn"] [0]; / /THIS.RESPONSE.WRITE () this.path ""); this.response.write ("
"); this.Response.write (String) Result.properties ["CN" ] [0]); this.Response.write ("
"); return true;}}}}