Akshit Soota Akshit Soota - 4 months ago 20
Vb.net Question

Verifying user details and auto-login Windows

I've see this application which can dig out our User Name from somewhere and asks our password. To be on the safe side, I typed my wrong password and it could cross-check that it was a wrong password and it asked me to type the right password. My question is:


  1. How do you dig out logged in user's User Name?

  2. How do you verify if a password given matches with the one really used to log into windows?

  3. How do we auto-login by providing these verified details you say at a specific time by regularly checking the time using a timer?



Is this even possible in VB.NET

Thanks in Advance

Answer

This function will authenticate a username and password against the active directory. You will need to import the System.DirectoryServices namespace. You'll also need to specify the LDAP path for the domain in the "domain" var, such as "dc=mydomain,dc=com".

Also, have a look at the My.User.* stuff.

Private Function Authenticate(userName As String, password As String, domain As String) As           Boolean
    Dim authentic As Boolean = False
    Try
        Dim entry As New DirectoryEntry("LDAP://" & domain, userName, password)
        Dim nativeObject As Object = entry.NativeObject
        authentic = True
    Catch generatedExceptionName As DirectoryServicesCOMException
    End Try
    Return authentic
End Function