BP Forums
making a windows login system - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: VB.NET (Visual Basic 2010/2008) (https://bpforums.info/forumdisplay.php?fid=8)
+----- Forum: Programming Help (https://bpforums.info/forumdisplay.php?fid=9)
+----- Thread: making a windows login system (/showthread.php?tid=538)



making a windows login system - Bradley - 05-28-2012

Hi,
Thanks for taking the interest in this post. I am trying to make a system Login using windows username and password I have got the code for the username already which is

Code:
Public Class form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = System.Environment.UserName
    End Sub
End Class


What I need is how to confirm the windows password is correct

Example

If John had an account on a windows machine the username will display as John
And then he enters his password the same as he would in windows it then checks Johns permissions and displayers the appropriate form

2 forms

1 Administrator
2 standard users

The code to verify the users rights I have used the following

Code:
Public Class form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
            TextBox2.Text = "Administrator"
        Else
            TextBox2.Text = "Standard"
        End If
    End Sub
End Class


So the only missing peace to the puzzle is confirming the password

Any help is grateful or if you could give me guidance on where to get this information

Kind Regards

Bradley


Re: making a windows login system - brandonio21 - 05-28-2012

Hey Bradley.

For obvious reasons, there is no one simple way to retrieve the data of the currently logged in user, as MS does not want people to simply code applications that steal security information. I have never tried to do this sort of thing, but I think that this article may help you:

<!-- m --><a class="postlink" href="http://www.dotnet-snippets.com/dns/check-windows-password-SID582.aspx">http://www.dotnet-snippets.com/dns/chec ... ID582.aspx</a><!-- m -->

EDIT: Here is another article you may find handy:

<!-- m --><a class="postlink" href="http://vbnet.mvps.org/index.html?code/network/acceptsecuritycontext.htm">http://vbnet.mvps.org/index.html?code/n ... ontext.htm</a><!-- m -->


Re: making a windows login system - Bradley - 05-29-2012

Many thanks for your help,
It looks a good code and most of it works but 1 line there is only 1 error

Code:
Public Function IsNTPasswordValid(ByVal Username As String, ByVal Password As String, Optional ByVal Domain As String = "") As Boolean
            Dim Token As New IntPtr
            LogonUser(Username, Domain, Password, LogonType.LOGON32_LOGON_INTERACTIVE, 0, Token)
            CloseHandle(Token)
            If Token.ToInt32 <> 0 Then Return True
        End Function

it states function IsNTPasswordValid don't return a value on all code paths are you missing a "Return" statement any help would be appricated but other than that fucntion the code is excepted any reasion why this maybe the case

Kind Regards
Bradley


Re: making a windows login system - brandonio21 - 05-29-2012

I believe that simply editing the code and adding in one line should do the trick!

Code:
Public Function IsNTPasswordValid(ByVal Username As String, ByVal Password As String, Optional ByVal Domain As String = "") As Boolean
            Dim Token As New IntPtr
            LogonUser(Username, Domain, Password, LogonType.LOGON32_LOGON_INTERACTIVE, 0, Token)
            CloseHandle(Token)
            If Token.ToInt32 <> 0 Then
                Return True
            Else
                Return False
             End If
        End Function