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 739195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:22:20+00:00 2026-05-14T08:22:20+00:00

Okay so I am trying to compare a login textbox password and username with

  • 0

Okay so I am trying to compare a login textbox password and username with a custom validator using linq to get information from the database it always returns false though on the validator could someone please tell me where my code below is going wrong. This will be very much appreciated… thank you in advanced…

protected void LoginValidate(object source, ServerValidateEventArgs args)
{
    TiamoDataContext context = new TiamoDataContext();

    var UsernameCheck = from User in context.Users
                      where User.Username == TextBoxLoginUsername.Text && User.Password == TextBoxLogInPassword.Text
                      select User.Username;

    var PasswordCheck = from User in context.Users
                    where User.Username == TextBoxLoginUsername.Text && User.Password == TextBoxLogInPassword.Text
                    select User.Password;

    String test1 = PasswordCheck.ToString();
    String test2 = UsernameCheck.ToString();

    if (test1 == TextBoxLogInPassword.Text && test2 == TextBoxLoginUsername.Text)
    {
        args.IsValid = true;
        Session["Username"] = TextBoxLoginUsername;
        Response.Redirect("UserProfile.aspx");

    }
    else 
    {
        args.IsValid = false;
    }

}

I dont know where I am going wrong I know its most probably some sort of silly mistake and me being inexperienced at this…

  • 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-05-14T08:22:20+00:00Added an answer on May 14, 2026 at 8:22 am

    UsernameCheck and PasswordCheck are going to be collections, not single values. Therefore the ToString() method isn’t returning what you think it should.

    It’s probably returning "IEnumerable<string>"

    You need to force your LINQ queries to return a single result rather than a collection.

    var user = context.Users.Where(u => u.Username==TextBoxLoginUsername.Text && 
                                        u.Password == TextBoxLogInPassword.Text)
                   .FirstOrDefault();
    
    string userNameCheck = user.Username;
    string passwordCheck = user.Password;
    

    As a side note, this is why using the var keyword is a little dangerous if you’re not absolutely positive of the return type of the statement you’re writing. If you would change your vars to strings, the compiler would have caught the type mismatch at compile time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay so what I'm trying to do is get the filename from OpenFileDialog/SaveFileDialog, only
Okay, I'm trying to get ActionBarSherlock working, so I imported the library by: Creating
Okay, so I am trying to wrap my head around how to get stuff
Okay I'm trying to move from VB to C# with mixed success. I'm getting
Okay... I'm getting kind of desperate trying to get this code to work with
Okay I am trying to make minecraft mods using eclipse. I used this video
Okay so I have been trying to get into IoC lately. However, I keep
Okay, so I'm trying to create a Order Posts by Type using jQuery JSON
Okay I'm trying to have a custom keypad pop-up when I want to enter
Okay so I am trying to make a histogram from a three dimensional array

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.