Results 1 to 2 of 2

Thread: [VS2013] Help me simplify the code

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2011
    Posts
    66

    [VS2013] Help me simplify the code

    Hello. I have a login form code that checks for username and password:

    Code:
                int i;
    
                for (i = 0; i < database1DataSet.users.Count; i++)
                {
                    if (database1DataSet.users.Rows[i][1].Equals(txtUser.Text))
                    {
                        if (database1DataSet.users.Rows[i][2].Equals (txtPassword.Text))
                        { MessageBox.Show("Access granted"); }
                }
    I know that this is a stupid way to execute a user and password check (the for i), but I searched google for hours, and did not find any better solution for my project.

    Please help me simplifying this code

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    Re: [VS2013] Help me simplify the code

    Generally you wouldn't retrieve all the user data into the application and than compare the user input to every row. Rather you would send the user input to the database and let it do the comparison, then return a single Boolean or number. I usually return a count, which will be 0 for a failed login and 1 for success. For an example, follow the CodeBank link in my signature below and check out my thread on WinForms Login.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width