Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Heres the codes:

VB
If txtpassword.Text <> pass Or txtusername.Text <> username Then

                    MsgBox("Invalid password or username,Please Change!", MsgBoxStyle.Information)
                    txtpassword.Clear()
                    txtusername.Clear()
                    trycount += 1
                    If trycount = 3 Then
                        MessageBox.Show("Wrong Password")
                        End
                    End If

                    Exit Sub
                Else

                    With frmMain
                        .lblfullname.Text = fullname
                        .lblposition.Text = position
                    End With
                    MsgBox("Successfully Logged In", MsgBoxStyle.Information)
                    frmMain.Show()
  End If

            Next
        End With

    End Sub
Posted
Updated 23-Nov-13 0:35am
v3
Comments
OriginalGriff 23-Nov-13 6:11am    
What "login Validation created?" are you talking about?
I can't see that in your code fragment, so I can't begin to say: "You need to do this" to fix it.
Use the "Improve question" widget to edit your question and provide better information.

Well, that's really up to you, not us.
There are two reasons why:
1) txtpassword.Text is not the same as pass
2) txtusername.Text is not the same as username

Since we have no idea what is in any of those values, you need to start by looking at them in the debugger.
Put a breakpoint on the first line of the above code and run your program.
When you try to log in, the breakpoint should trigger and you program will stop.
In VS, hover your mouse over the values in the Text properties, and the pass and username variables and see what values they do contain.
If they look wrong, then look back in your code and try to work out where they went wrong.
If they look right, single step the debugger and see if the code agrees with you. If it does, run it on and see if the same code executes again for some reason. If it doesn't, then look again, rather more closely...
 
Share this answer
 
Actaully from your code sample i do not understand where the problem is. But i write some way how to code for authenticating user. If you do so and unit test then easily you understand where the problem is.

step 1> You should write a IsUserExists methold to your business layer as follows

C#
public class UserBusinessService
{
     //You may user dependency injection for writing decouple code.
     private IUserDataService _userDataService = new UserDataService();
     
     public bool IsUserExists(string userName, string password)
     {
         //if user exists data service return User object otherwise return null
         User user = _userDataService.GetUser(userName, password);
         return user != null;
     }
}

After implementing that type of code, you should unit test your code so that you can understand any problem there or not.

From your WindowsForm/WPF UI class you should call it and verify user properly

C#
public class LoginForm:WindowsFormBase
{
   //you may use dependency injection, IOC container, ServiceFactory pattern
   private readonly IUserBusinessService _userService= new UserBusinessService();
   public void Login_Click(object sender, EventArgs e)
   {
        bool success = _userService.IsUserExists(txtUserName.Text, txtPassword.Text);
        if(!success)
        {
            MessageBox.Show("User name/password is incorrect. Please check");
        }
        else
        {
           //write your code after successfully authenticated user
        }       
   }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900