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

  • Home
  • SEARCH
  • 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 7931049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:36:33+00:00 2026-06-03T20:36:33+00:00

I try to check user is exist or not.I try: public static bool GetUser(string

  • 0

I try to check user is exist or not.I try:

public static bool GetUser(string tblName, string UserName,string Password,string Usertype)
        {
            try
            {

                using (SqlConnection con = Connection.GetConnection())
                {
                    using (SqlCommand cmd = con.CreateCommand())
                    {
                       cmd.CommandText = "select count(UserName) from " + tblName + " where Password=" + Password + " and usertype=" + Usertype + " and username="+ UserName + "";
                        object obj = cmd.ExecuteScalar();
                        if (obj != null)
                            return true;
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

        }

When I call this method I got a following error.
My Error
connection is successfully established and I call this method like this.

bool Check = UserLogin.GetUser("OnlineCertificationLogin", "admin", "admin", "Admin");

My table structure is

My Table Structure
Unable to find my mistake.Thanks.

  • 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-03T20:36:35+00:00Added an answer on June 3, 2026 at 8:36 pm

    You’re not quoting the values, so your SQL ends up as:

    select count(UserName) from OnlineCertificationLogin
    where Password=admin and usertype=admin and username=Admin
    

    Don’t fix this by adding quotes. Your code would then work for the sample given, but you’d be vulnerable to SQL injection attacks. Instead, you should fix this using a parameterized query – see SqlCommand.Parameters for more information and an example.

    Although you can’t parameterize the table name, you should make sure that it only ever comes via trusted code – not via user input, for example, as otherwise you’ve got exactly the same SQL injection problem again.

    Note that you also shouldn’t be storing passwords in plain text like that.

    I strongly recommend that you get hold of a book on security – Beginning ASP.NET Security might be up your street. (I have a copy but I confess haven’t read it much – I’ve listened to Barry talking about security though, and he explains it all very clearly.)

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

Sidebar

Related Questions

I try to make a registration form. When user post the fields, i check
To see what I want, check out the regex I'm using. I'll try to
I am using C# application to authenticate and check Active Directory user which locates
I commit all my files into bitbucket. i try check in,revert file i deleted
What the heck does obstructed mean when you try to check into Subversion? I
try: spam.foo except AttributeError: do_somthing() (Is it wise to check an attribute like that
I try to create unit test cases to check my table values are correct
What test text do you try and type into your web forms to check
Try to see which cast is faster (not necessary better): new c++ case or
I try to generate a HQL query that include user with a empty appoinment

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.