protected void btnLogon_Click(object sender, EventArgs e) { // Path to you LDAP directory server. // Contact your network administrator to obtain a valid path. string adPath = "LDAP://172.30.1.227/DC=corp,DC=fetec,DC=dsv,DC=ru"; LdapAuthentication adAuth = new LdapAuthentication(adPath); try { if (true == adAuth.IsAuthenticated(txtDomainName.Text, txtUserName.Text, txtPassword.Text)) { // Retrieve the user's groups string groups = adAuth.GetGroups(); // Create the authetication ticket FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, // version txtUserName.Text, DateTime.Now, DateTime.Now.AddMinutes(60), false, groups); // Now encrypt the ticket. string encryptedTicket = FormsAuthentication.Encrypt(authTicket); // Create a cookie and add the encrypted ticket to the // cookie as data. HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); // Add the cookie to the outgoing cookies collection. Response.Cookies.Add(authCookie); // Redirect the user to the originally requested page Response.Redirect( FormsAuthentication.GetRedirectUrl(txtUserName.Text, false)); } else { lblError.Text = "Authentication failed, check username and password."; } } catch (Exception ex) { lblError.Text = "Error authenticating. " + ex.Message; } }
private bool AuthAuUser(string username, string pwd) { #if BYPASS_AU_AUTH return true; #endif if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(pwd)) return false; String adPath = "LDAP://auburn.edu/DC=auburn,DC=edu"; LdapAuthentication adAuth; adAuth = new LdapAuthentication(adPath); try { if (adAuth.IsAuthenticated("auburn", username, pwd) == true) return true; else return false; } catch (Exception ex) { return false; } }