<%@ 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="VB" %>
<script runat="server">
Dim initLDAPPath = "dc=tc, dc=thaicreate, dc=com"
Dim initLDAPServer = "192.168.0.5"
Dim initShortDomainName = "tc"
Dim strErrMsg
Public Function MD5(ByVal strString As String) As String
Dim ASCIIenc As New ASCIIEncoding
Dim strReturn As String
Dim ByteSourceText() As Byte = ASCIIenc.GetBytes(strString)
Dim Md5Hash As New MD5CryptoServiceProvider
Dim ByteHash() As Byte = Md5Hash.ComputeHash(ByteSourceText)
strReturn = ""
For Each b As Byte In ByteHash
strReturn = strReturn & b.ToString("x2")
Next
Return strReturn
End Function
Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim DomainAndUsername As String = ""
Dim strCommu As String
Dim flgLogin As Boolean = False
strCommu = "LDAP://" & initLDAPServer & "/" & initLDAPPath
DomainAndUsername = initShortDomainName & "\" & txtUser.Text
Dim entry As New DirectoryEntry(strCommu, DomainAndUsername, txtPwd.Text)
Dim obj As Object
Try
obj = entry.NativeObject
Dim search As New DirectorySearcher(entry)
Dim result As SearchResult
search.Filter = "(SAMAccountName=" + txtUser.Text + ")"
search.PropertiesToLoad.Add("cn")
result = search.FindOne()
If result Is Nothing Then
flgLogin = False
strErrMsg = "Please check user/password"
Else
flgLogin = True
End If
Catch ex As Exception
flgLogin = False
strErrMsg = "Please check user/password"
End Try
IF flgLogin = True
Me.lbDisplay.Text = "Welcome " & txtUser.Text
Else
Me.lbDisplay.Text = strErrMsg
End IF
End Sub
</script>
<html>
<head>
<title>ThaiCreate.Com AD/LDAP (Active Directory)</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>