Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7721215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:52:02+00:00 2026-06-01T03:52:02+00:00

I need to validate if the user’s provided information is in the database, i’ve

  • 0

I need to validate if the user’s provided information is in the database, i’ve tried to enter the correct condition and its not working it returns an error that it cannot be found on the database. Can you check my code and tell me what’s going on? , I tried to debug it but the foreach loop continue to loop and does not go to if (isexist) statement

protected void btnSubmit_Click(object sender, EventArgs e)
    {
        token = FormsAuthentication.HashPasswordForStoringInConfigFile(txtUsername.Text.ToString() + txtAcctNo.Text.ToString(), "MD5");
        try
        {
            bool isExist = false;
            DataSet ds = new DataSet();
            ds = startService.getAllUsersWithoutFilter();
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dRow in ds.Tables[0].Rows)
                {

                    string userName = dRow["UserName"].ToString();
                    string acctNo = dRow["AccountNumber"].ToString();
                    string question = dRow["SecretQuestion"].ToString();
                    string answer = dRow["SecretAnswer"].ToString();

                    if (userName == txtUsername.Text.ToString() && acctNo == txtAcctNo.Text.ToString() && question == cboQuestion.Text.ToString() &&  answer == txtAnswer.Text.ToString())
                    {
                        isExist = true;
                    }
                    else
                    {
                        isExist = false;
                    }

                }

                if (isExist)
                {
                    startService.sendTokenizer(txtUsername.Text.ToString(), token);
                    //update database to change password to standard password
                    startService.inserUserActivity(txtUsername.Text.ToString(), txtAcctNo.Text.ToString(), "Password Reset Request", HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);
                    startService.requestReset(txtUsername.Text.ToString(), txtAcctNo.Text.ToString(), token);

                    lblMessage.ForeColor = System.Drawing.Color.Green;
                    lblMessage.Text = "<br>We have sent an email to you for the instructions to reset your password. Please check your email.";
                }
                else
                {
                    this.lblMessage.ForeColor = System.Drawing.Color.Red;
                    this.lblMessage.Text = "<br><br>Error - Information cannot be found. Please check and try again. Make sure all the fields are correct.";
                }

            }
        }
        catch
        {
            lblError.Text = "There was an error occured while processing your request. Please try again later.";
        }

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T03:52:04+00:00Added an answer on June 1, 2026 at 3:52 am

    I think all you need is to break out of your foreach loop when you set isExist to true.

    if (userName == txtUsername.Text.ToString() && acctNo == txtAcctNo.Text.ToString() && question == cboQuestion.Text.ToString() &&  answer == txtAnswer.Text.ToString())
    {
        isExist = true;
        break; //Found it, so stop looking.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to validate that user provided data for oracle account information is correct.
I read that you do not need to validate or sanitize user's input if
I need to validate the user input of a JSpinner , and if invalid,
I need to validate two user input fields against each other in seam. Field1
For example, if I have a user model and I need to validate login
I need to validate an XML string (and not a file) against a DTD
I need to validate an XML agaist a schema. I tried XML::SAX::ParserFactory; XML::Validator::Schema and
I need to validate the LDAP user by checking if there exists such a
I need to validate human user by using captcha in PHP. Also the critical
I have a Datagridview, on which I need to validate the user input on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.