Making a Password form

Hello everyone, My question is regarding how I would make it where someone has to enter the right name and password inorder to bring up the next form, like they would have their own account as well and it would bring the form up when the correct info is entered. I am using VB Expresws 2005 , Thanks!

Answer this question

Making a Password form

  • jhered

    This would just be a matter of creating a form... we'll call it PasswordForm that contains a pair of TextBoxes and a button... the whole thing would be called/displayed from a parent form or class that would inspect the specified credentials and if they are ok, continue executing, otherwise abort without continuing.

    Another option might be to have the PasswordForm itself check the username and password itself and return a single value back to the calling form via an exposed property or method.

    You can find a quick example of doing some of this here. Sadly this example only deals with the password (no username) however the underlying concepts are still the same.



  • Romantic_touch

    Try something like this:

    First add a loginform to your project. The rest you should be able to figure out.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

    If UsernameTextBox.Text = "username" And PasswordTextBox.Text = "password" Then

    Me.Close()

    Form1.show()

    ElseIf UsernameTextBox.Text <> "username" Then

    MsgBox("Name Incorrect")

    ElseIf PasswordTextBox.Text <> "password" Then

    MsgBox("Password Incorrect")

    End If

    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click

    Me.Close()

    End Sub



  • GeoffNin

    word haha not sure what was wrong but its working now, thanks alot dude!
  • KatyG

    hey I got it to work great, but its not showing form2 when the log in info is entered
  • David S. Anderson

    Do u have form2.show

    it should show your form when u click ok if the input matches your username and password in your code.



  • jrsearles

    Yeah man I have form2.show () and when the OK button is clicked it does nothing hmm
  • RichardW411084

    Just a piece of advice when it comes to trying code from someone who is also fairly new to VB.net.

    Sometimes code won't run and then sometimes it will the next time.  i don't understand why but it does.

    and also sometimes you need to publish your app and try it, what may not work in debug may work for real and vice-versa.



  • sfabriz

    Thanks for the info bro, very much appreciated!
  • aashta

    js06 wrote:

    Try something like this:

    First add a loginform to your project. The rest you should be able to figure out.

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click

    If UsernameTextBox.Text = "username" And PasswordTextBox.Text = "password" Then

    Me.Close()

    Form1.show()

    ElseIf UsernameTextBox.Text <> "username" Then

    MsgBox("Name Incorrect")

    ElseIf PasswordTextBox.Text <> "password" Then

    MsgBox("Password Incorrect")

    End If

    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click

    Me.Close()

    End Sub

    So just insert that into the log in form correct


  • Making a Password form