Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
making a windows login system
#1
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
#2
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 -->
My Blog | My Setup | My Videos | Have a wonderful day.
#3
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
#4
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
My Blog | My Setup | My Videos | Have a wonderful day.


Possibly Related Threads…
Thread Author Replies Views Last Post
  how do you make a register system in VB using Dropbox Cecilio 2 13,951 08-15-2013, 08:14 AM
Last Post: Cecilio
  help with making a simple program Yevzor 2 14,794 03-29-2013, 05:04 AM
Last Post: Yevzor
  i am getting a problem with brandonio's login form mnxford 1 9,099 03-27-2013, 10:55 AM
Last Post: mnxford
  Windows API Code Pack 1.1 brco900033 1 8,710 10-30-2012, 08:12 PM
Last Post: brandonio21
  little help! working with system time jochen29 1 9,321 09-23-2012, 10:02 AM
Last Post: Vinwarez
  Help w/ my new operating system Gamester699 5 20,270 07-24-2012, 12:50 PM
Last Post: Vinwarez
  I need help making a calculator like a windows calculator Xandereliteinsight 4 17,924 07-24-2012, 07:53 AM
Last Post: Moldraxian
  I need help making a webbowser? bryan13roblox 1 8,882 03-24-2012, 01:44 PM
Last Post: xolara
  Plugin System? zmanalpha 2 11,692 12-19-2011, 02:56 PM
Last Post: zmanalpha
  i need help on making a launcher with auto updating function jamietjeh 2 12,364 12-16-2011, 07:24 PM
Last Post: xolara

Forum Jump:


Users browsing this thread: 1 Guest(s)