I'm trying to make this login but I'm having some trouble. This is my code so far. I put this code into the login button:
Private Sub loginbutton_Click(sender As Object, e As EventArgs) Handles loginbutton.Click
1 Dim InputUser As String
2 Dim InputPass As String
3 Dim Correctu As String
4 Dim Correctp As String
5 InputUser = txtLogin.Text
6 InputPass = txtLoginPassword.Text
7 Correctu = "Daniel"
8 Correctp = "apple"
9 If InputUser = Correctu Then islogincorrect.Text = "Login is Correct!"
10 If InputPass = Correctp Then islogincorrect.Text = "Login is Correct!" Else
11 If InputUser <> Correctu Then
12 islogincorrect.Text = "Login is Not Correct!"
13 End If
15 End Sub
Im trying to make it so that if the username and password match what they are supposed to be, then it will say login is correct, and if not display login is not correct. InputUser is the username box. InputPass is the password box. The Correctu is just saying what the correct username should be and Correctp is saying what the correct password should be. I'm having trouble somewhere on lines 9 down saying that if the username and password are what they are supposed to be, it would say login correct but thats not working. So if sombody could please help me that would be great. Thanks!
You care correct on where the problem starts. You are asking two independent questions in those statements.
1) is InputUser = Daniel. If so, "Correct"
2) is InputPass = apple. If so, "Correct"
As you have noticed, you only have to answer one of those correctly in order to get a "Correct" result. You want BOTH of them to be correct. You need to "And" the two statements.
If InputUser = Correctu And InputPass = Correctp Then
'Both user and password are correct
isLoginCorrect.Text = "Login is Correct!"
'One or both are not correct
isLoginCorrect.Text = "Login is Not Correct!"
Another way to simplify a couple of lines of code is to specify the values of your variables when you declare them:
Dim Correctu as String = "Daniel"
You could eliminate all of your variables all together if you wanted. There are many ways to do it, I was just sharing some different examples. In the end you want to do what makes sense and is easy to follow. Also, you can never use too many comments!!!!
If txtLogin.Text = "Daniel" And txtLoginPassword.Text = "apple" Then