Results 1 to 6 of 6

Thread: Windows Login

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Dublin
    Posts
    35
    I am trying to put a login dialog on my application.

    In order to Authenticate the username and password I want to use the windows login.

    Does anybody know if this is possible and If so how do I do it.

    Regards

  2. #2
    Addicted Member Nice's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    144

    Cool

    have a look@this sample code:

    Put this in a module:

    Option Explicit

    Declare Function GetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, _
    nSize As Long) As Long

    Private Declare Function WNetVerifyPassword Lib "mpr.dll" Alias _
    "WNetVerifyPasswordA" (ByVal lpszPassword As String, _
    ByRef pfMatch As Long) As Long

    Public Function GetWindowsLoginUserID() As String
    Dim rtn As Long
    Dim sBuffer As String
    Dim lSize As Long

    sBuffer = String$(260, Chr$(0))
    lSize = Len(sBuffer)
    rtn = GetUserName(sBuffer, lSize)
    If rtn Then
    sBuffer = Left$(sBuffer, lSize)

    'Reformat string
    If InStr(sBuffer, Chr$(0)) Then
    sBuffer = Left$(sBuffer, InStr(sBuffer, Chr$(0)) - 1)
    End If

    GetWindowsLoginUserID = sBuffer
    Else
    'Error!
    GetWindowsLoginUserID = ""
    End If

    End Function

    Public Function VerifyWindowsLoginUserPassword _
    (ByVal Password As String) As Boolean
    Dim rtn As Long, Match As Long
    rtn = WNetVerifyPassword(Password, Match)
    If rtn Then
    VerifyWindowsLoginUserPassword = False
    Else
    VerifyWindowsLoginUserPassword = (Match <> 0)
    End If
    End Function

    and this in the form:

    Private Sub Command1_Click()
    If VerifyWindowsLoginUserPassword(Text2.Text) Then
    MsgBox "Pwd OK"
    Else
    MsgBox "Wrong Pwd"
    End If
    End Sub

    Private Sub Form_Load()
    Text1.Text = GetWindowsLoginUserID
    End Sub

  3. #3
    Fanatic Member faisalkm's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    752
    nialler.....The user of ur app uses ur application only after logging in to Windows then whats the meaning in asking for the windows login in ur app?
    Faisal Muhammed
    Homepage:I Started making it in 1994 ...Still Under Construction
    Using

    Visual Basic 6.0 Enterprise SP5
    Embedded Visual Basic 3.0
    SQL Server 2000
    Windows 2000 Proff
    Delphi 6.0


    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  4. #4
    Fanatic Member ExtremePimpness's Avatar
    Join Date
    Jan 2001
    Location
    Indianapolis, Indana - USA
    Posts
    550
    Mabey nailer was thinking of a multiuser computer with one logon. in that case the only person that can use the app he designs is the one who setup the password, Or if you leave the computer unattended while logged on.
    It is a minor security percaution and i am sure that nailer has his reasons.


    There are no stupid questions, just stupid people to interperate them.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Dublin
    Posts
    35

    Thanks for the Help!

    Thanks everybody for the help.

    The reason I need to know is that the application, at certain points, will require certain administrative rights, so digital signaturing is required, which is no good if somebody can just walk over to the computer and do it for you.

    Thanks, Nice, for the help, much appreciated!

    Regards

  6. #6
    Fanatic Member ExtremePimpness's Avatar
    Join Date
    Jan 2001
    Location
    Indianapolis, Indana - USA
    Posts
    550
    my post was directed towards faisalkm.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width