Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protected void Button1_Click1(object sender, EventArgs e)
- {
- string dominName = "ldap://domain.com:121";
- string userName = "guest";
- string password = "testlogin";
- if (true == AuthenticateUser(dominName, userName, password))
- {
- Response.Redirect("default.aspx");
- }
- else
- {
- Response.Write("Invalid user name or Password!");
- }
- }
- public bool AuthenticateUser(string domain, string username, string password)
- {
- DirectoryEntry entry = new DirectoryEntry(domain, username, password);
- try
- {
- DirectorySearcher search = new DirectorySearcher(entry);
- search.Filter = "(sAMAccountName=" + username + ")";
- search.PropertiesToLoad.Add("cn");
- Response.Write(domain);
- SearchResult result = search.FindOne();
- if (null == result)
- {
- return false;
- }
- }
- catch (Exception ex)
- {
- return false;
- throw new Exception("Error authenticating user." + ex.Message);
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement