<%@ Assembly Name="System.DirectoryServices, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"%> <%@ Import Namespace="System.DirectoryServices"%> <%@ Import Namespace="System.Security.Cryptography"%> <%@ Import Namespace="System.Text"%> <%@ Page Language="C#" %> <script runat="server"> string initLDAPPath = "dc=tc, dc=thaicreate, dc=com"; string initLDAPServer = "192.168.0.5"; string initShortDomainName = "tc"; string strErrMsg; public string MD5(string strString) { ASCIIEncoding ASCIIenc = new ASCIIEncoding(); string strReturn; byte[] ByteSourceText = ASCIIenc.GetBytes(strString); MD5CryptoServiceProvider Md5Hash = new MD5CryptoServiceProvider(); byte[] ByteHash = Md5Hash.ComputeHash(ByteSourceText); strReturn = ""; foreach (byte b in ByteHash) { strReturn = (strReturn + b.ToString("x2")); } return strReturn; } void Page_Load(object sender, EventArgs e) { } protected void btnLogin_Click(object sender, System.EventArgs e) { string DomainAndUsername = ""; string strCommu; bool flgLogin = false; strCommu = ("LDAP://" + (initLDAPServer + ("/" + initLDAPPath))); DomainAndUsername = (initShortDomainName + ("\\" + txtUser.Text)); DirectoryEntry entry = new DirectoryEntry(strCommu, DomainAndUsername, txtPwd.Text); object obj; try { obj = entry.NativeObject; DirectorySearcher search = new DirectorySearcher(entry); SearchResult result; search.Filter = ("(SAMAccountName=" + (txtUser.Text + ")")); search.PropertiesToLoad.Add("cn"); result = search.FindOne(); if ((result == null)) { flgLogin = false; strErrMsg = "Please check user/password"; } else { flgLogin = true; } } catch (Exception ex) { flgLogin = false; strErrMsg = "Please check user/password"; } if ((flgLogin == true)) { this.lbDisplay.Text = ("Welcome " + txtUser.Text); } else { this.lbDisplay.Text = strErrMsg; } } </script> <html> <head> <title>ThaiCreate.Com</title> </head> <body> <form id="form1" runat="server"> <asp:TextBox ID="txtUser" runat="server" Width="147px"></asp:TextBox> <asp:TextBox ID="txtPwd" runat="server" Width="147px" TextMode="Password"></asp:TextBox> <asp:Button ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click" /> <br /> <asp:Label ID="lbDisplay" runat="server"></asp:Label> </form> </body> </HTML>
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท