LDAP for logon

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello All

I am trying to write a vb.net windows application, this application will have a logon that I want to "tie" to the Active Directory that is running on the network. Where do I look to get started integrating with LDAP. Is it easy to program the Logon feature? Is there some sample code out there

Thank
Brad
 
No answers here I'm afraid Brad, but just to say that I don't really
understand exactly what it is you're trying to achieve. I have a windows
forms app that checks who the logged in user is and only allows access if
they are a member of a particular AD group (or groups). Is that what you're
after? If not, it'll probably be worth a repost with an example of what
functionality you want.


Brad said:
Hello All,

I am trying to write a vb.net windows application, this application will
have a logon that I want to "tie" to the Active Directory that is running on
the network. Where do I look to get started integrating with LDAP. Is it
easy to program the Logon feature? Is there some sample code out there?
 
OK. Some functions that I use....

Imports System.Security.Principal

'Returns current user
Public Function CurrentUser()
Dim pos As Integer, fullname As String
fullname = System.Security.Principal.WindowsIdentity.GetCurrent().Name
'Just to get at the username after the 'domainname\' Should really use
Substring instead of Mid
pos = InStr(fullname, "\", CompareMethod.Text)
CurrentUser =
Mid(System.Security.Principal.WindowsIdentity.GetCurrent().Name, pos + 1)
End Function


'To test whether user is a member of a group
Private Function InGroup(ByVal grp As String) As Boolean
Dim id As WindowsIdentity
id = WindowsIdentity.GetCurrent()
Dim p As New WindowsPrincipal(id)
InGroup = p.IsInRole("YourDomainName\" + grp)
End Function

....and a sample Sub Main()....

Sub Main()
dim msg as string
If InGroup("AppUsers") Then
Application.Run(New YourMainForm)
Else
msg = "You are not a registered user. Please go away."
MessageBox.Show(msg, "Invalid user", MessageBoxButtons.OK)
End If
End Sub
 
excellent
Rob Oldfield said:
OK. Some functions that I use....

Imports System.Security.Principal

'Returns current user
Public Function CurrentUser()
Dim pos As Integer, fullname As String
fullname = System.Security.Principal.WindowsIdentity.GetCurrent().Name
'Just to get at the username after the 'domainname\' Should really use
Substring instead of Mid
pos = InStr(fullname, "\", CompareMethod.Text)
CurrentUser =
Mid(System.Security.Principal.WindowsIdentity.GetCurrent().Name, pos + 1)
End Function


'To test whether user is a member of a group
Private Function InGroup(ByVal grp As String) As Boolean
Dim id As WindowsIdentity
id = WindowsIdentity.GetCurrent()
Dim p As New WindowsPrincipal(id)
InGroup = p.IsInRole("YourDomainName\" + grp)
End Function

...and a sample Sub Main()....

Sub Main()
dim msg as string
If InGroup("AppUsers") Then
Application.Run(New YourMainForm)
Else
msg = "You are not a registered user. Please go away."
MessageBox.Show(msg, "Invalid user", MessageBoxButtons.OK)
End If
End Sub
 
Back
Top