CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    May 2006
    Location
    London (UK)
    Posts
    138

    use Windows Username and Password to login my app...

    Hi,

    I don't want to store username and password into the database or file. I want that user will login through the logged in UserName Password and domain. for e.g.

    If User ABC is logged into the system, then once he open the app, he will prompt for password, so that username will be the windows username and password has to be entered correctly.

    Please let me know how I can achieve it....




    .

    Hope that Helps a Bit, but Sorry if it doesn't.
    Dont forget to Rate the Post...


    Thanks & Regards
    Manu Raj

    Nothings is Impossible in this World even Impossible says "I M possible"...

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: use Windows Username and Password to login my app...

    All I'll give you is that you can use either the GetUserName or the GetUserNameEx API s to get the User name(s), to get the password, hmm I think that'll be too much of a risk posting such code on a public forum, at least IMHO.

  3. #3
    Join Date
    May 2006
    Location
    London (UK)
    Posts
    138

    Unhappy Re: use Windows Username and Password to login my app...

    Am still struggling....

    Hope that Helps a Bit, but Sorry if it doesn't.
    Dont forget to Rate the Post...


    Thanks & Regards
    Manu Raj

    Nothings is Impossible in this World even Impossible says "I M possible"...

  4. #4
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: use Windows Username and Password to login my app...

    With what ¿ It cannot be with the Username ( not if you followed my advice ). As I also said ( to you ) in this thread and in numerous PMs, I don't think it's allowed to post such info about the Password here, and i don't want to ( and not going to ) break any rules..

  5. #5
    Join Date
    May 2006
    Location
    London (UK)
    Posts
    138

    Re: use Windows Username and Password to login my app...

    Hey....
    Hurrey I just got it now......


    Thanks Hannes...



    .

    Hope that Helps a Bit, but Sorry if it doesn't.
    Dont forget to Rate the Post...


    Thanks & Regards
    Manu Raj

    Nothings is Impossible in this World even Impossible says "I M possible"...

  6. #6
    Join Date
    May 2006
    Location
    London (UK)
    Posts
    138

    Talking Re: use Windows Username and Password to login my app...

    I use below code... It will not brings up the password but it will validate the user...


    Code:
     Public Declare Function NetUserChangePassword Lib "netapi32.dll" (ByVal sDomain As String, ByVal sUserName As String, ByVal sOldPassword As String, ByVal sNewPassword As String) As Long

    Code:
     Public Function UserValidate(sUserName As String, sPassword As String, Optional sDomain As String) As Boolean
    Dim lReturn As Long
    Const NERR_BASE = 2100
    Const NERR_PasswordCantChange = NERR_BASE + 143
    Const NERR_PasswordHistConflict = NERR_BASE + 144
    Const NERR_PasswordTooShort = NERR_BASE + 145
    Const NERR_PasswordTooRecent = NERR_BASE + 146
    Const NERR_Cant_Change = 5 '"User can't change password" is checked
    	
      If Len(sDomain) = 0 Then
    	sDomain = Environ$("USERDOMAIN")
      End If
      
      'Call API to check password.
      lReturn = NetUserChangePassword(StrConv(sDomain, vbUnicode), StrConv(sUserName, vbUnicode), StrConv(sPassword, vbUnicode), StrConv(sPassword, vbUnicode))
      
      'Test return value.
      Select Case lReturn
    	Case 0, NERR_PasswordCantChange, NERR_PasswordHistConflict, NERR_PasswordTooShort, NERR_PasswordTooRecent
    	  UserValidate = True
    	Case 5
    	  UserValidate = False
    	  MsgBox "The user is not allowed to change passwords.  Please remove the restriction.", vbCritical, "System Error"
    	Case Else
    	  UserValidate = False
      End Select
    End Function
    Private Sub Command1_Click()
    If UserValidate(Text1.Text, Text2.Text, Text3.Text) = True Then
    	MsgBox "OK"
    Else
    	MsgBox "Not OK"
    End If
    End Sub

    Hope that Helps a Bit, but Sorry if it doesn't.
    Dont forget to Rate the Post...


    Thanks & Regards
    Manu Raj

    Nothings is Impossible in this World even Impossible says "I M possible"...

  7. #7
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: use Windows Username and Password to login my app...

    You can't use StrConv(), as far as I can tell. Need a byte-array


    'Converts a Unicode-String to a Unicode-Byte-Array.
    'Is used because VB always passes Strings as ANSI instead of Unicode.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  8. #8
    Join Date
    May 2006
    Location
    London (UK)
    Posts
    138

    Re: use Windows Username and Password to login my app...

    But it is working fine....

    Hope that Helps a Bit, but Sorry if it doesn't.
    Dont forget to Rate the Post...


    Thanks & Regards
    Manu Raj

    Nothings is Impossible in this World even Impossible says "I M possible"...

  9. #9
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792

    Re: use Windows Username and Password to login my app...

    Code:
    Dim uname As String
    uname = Environ$("Username")
    MsgBox "Username = " & uname
    Be nice to Harley riders...

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

Featured