Thursday, November 16, 2006

Authenticating LDAP user in VB.NET or ASP.NET

If you want to authenticate user against LDAP using VB.NET or ASP .NET.
Below is the function, you can try. Don't forget to import System.DirectoryServices in your codes.

Public Function AuthenticateUser(ByVal ldapServerName As String, ByVal username As String, ByVal password As String) As Boolean

Dim _ldapServerName = ldapServerName

Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & ldapServerName & _

"/uid=""" & username & """,ou=yourfullOU", "uid=""" & username & """,ou=yourfullOU", password, AuthenticationTypes.ServerBind)

Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)

Try

Dim mySearchResult As SearchResult = oSearcher.FindOne()

Return True


Catch e As Exception

MsgBox("Error is " & e.Message)

Return False

End Try

End Function
Add to Blink Add to Furl Add the post to Technorati Favourites Add to Simpy Add to Spurl Add to Yahoo MyWeb Add to del.icio.us Add to Digg It Social bookmark this!
0 comments

Wednesday, November 15, 2006

Visual Basic: Format Date And Time

Useful function for VB programmer to format date in standard strings

function ReturnFormattedTime (mytime)
Dim CurrentTime, nHour, nMinute, nSecond
Dim strHour, strMinute, strSecond

CurrentTime = mytime
nHour = Hour( CurrentTime )
nMinute = Minute( CurrentTime )
nSecond = Second( CurrentTime)


strHour = CStr( nHour )
if nHour < 10 then strHour = "0" & strHour

strMinute = CStr( nMinute )
if nMinute < 10 then strMinute = "0" & strMinute

strSecond = CStr( nSecond )
if nSecond < 10 then strSecond = "0" & strSecond

ReturnFormattedTime = strHour & ":" & strMinute & ":" & strSecond

end function



function ReturnFormattedDate (mydate)
Dim CurrentDate, nYear, nMonth, nDay
Dim strYear, strMonth, strDay


CurrentDate = mydate
nYear = Year( CurrentDate )
nMonth = Month( CurrentDate )
nDay = Day( CurrentDate )

strYear = CStr( nYear )

strMonth = CStr( nMonth )
if nMonth < 10 then strMonth = "0" & strMonth

strDay = CStr( nDay )
if nDay < 10 then strDay = "0" & strDay

ReturnFormattedDate = strDay & "/" & strMonth & "/" & strYear

end function


Tag:, , , , ,

Add to Blink Add to Furl Add the post to Technorati Favourites Add to Simpy Add to Spurl Add to Yahoo MyWeb Add to del.icio.us Add to Digg It Social bookmark this!
0 comments