c# - Pass values from plain-text to a method on button click -


i using below code login in using ldap authentication in asp.net. however, don't know how pass values plain-text code. want run through button click.

public class ldapauthentication {     private string _path;     private string _filterattribute;     public ldapauthentication(string path)     {         _path = path;      }     public bool isauthenticated(string domain, string username, string pwd)     {         string domainandusername = domain + @"\" + username;         directoryentry entry = new directoryentry(_path, domainandusername, pwd);          try         {             // bind native adsobject force authentication.             object obj = entry.nativeobject;             directorysearcher search = new directorysearcher(entry);             search.filter = "(samaccountname=" + username + ")";             search.propertiestoload.add("cn");             search.propertiestoload.add("mail");             searchresult result = search.findone();             if (null == result)             {                 return false;             }             //if (result != null)             //{             //    string mail = result.properties["mail"][0].tostring();              //}              // update new path user in directory             _path = result.path;             _filterattribute = (string)result.properties["cn"][0];             _filterattribute = (string)result.properties["mail"][0];         }         catch (exception ex)         {             throw new exception("error authenticating user. " + ex.message);         }         return true;     }     public string getgroups()     {         directorysearcher search = new directorysearcher(_path);         search.filter = "(cn=" + _filterattribute + ")";         search.filter = "(mail=" + _filterattribute + ")";         search.propertiestoload.add("memberof");         stringbuilder groupnames = new stringbuilder();         try         {             searchresult result = search.findone();             int propertycount = result.properties["memberof"].count;             string dn;             //int equalsindex, commaindex;              (int propertycounter = 0; propertycounter < propertycount;                  propertycounter++)             {                 dn = (string)result.properties["memberof"][propertycounter];                  //equalsindex = dn.indexof("=", 1);                 //commaindex = dn.indexof(",", 1);                 //if (-1 == equalsindex)                 //{                 //    return null;                 //}                 //groupnames.append(dn.substring((equalsindex + 1),                 //                  (commaindex - equalsindex) - 1));                 //groupnames.append("|");             }         }         catch (exception ex)         {             throw new exception("error obtaining group names. " +               ex.message);         }         return groupnames.tostring();     }  } 

this may oversimplification but...

 public void loginbutton_clicked(object sender, eventargs e) {     ldapauthentication auth = new ldapauthentication("yourpath");     if (auth.isauthenticated("yourdomain", txtid.text, txtpassword.text))     {         //login passed     } } 

i'm assuming using webforms , username textbox has id "txtid", , password textbox has id "txtpassword".

if not using webforms implementation different. spectacularbob mentioned, can't answer question until know ui framework using.


Comments

Popular posts from this blog

rewrite asp to php based on asp query -

android - questions about switching from C2DM to GCM -

visual studio 2010 - Error on RDLC Expression -