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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:42:40+00:00 2026-05-30T23:42:40+00:00

I want to make a simple login page, without register just a username and

  • 0

I want to make a simple login page, without register just a username and a password I used in the SQL database. this is what I wrote now for button1:

string connection_string = "Path to database";
SqlConnection connect = new SqlConnection();
connect.ConnectionString = connection_string;
connect.Open();
string sql = "Select * FROM Register where username=@username and password=@password";
SqlCommand 1 = new SqlCommand("username",textbox1User.text);
SqlCommand 2 = new SqlCommand("password",textbox2pass.text);

That’s what I have now. I need to do the rest of login page and if values are ok then I will be redirected on a page. but I also need to know how can I protect the page for not being allowed to access it by other users just by typing the url to file. So it should work only If I login.

  • 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-30T23:42:41+00:00Added an answer on May 30, 2026 at 11:42 pm

    First, I must congratulate you on wanting to use parameters for your SQL. A lot of beginners do not do this, leading to horrible SQL Injection attacks.

    Second, you really should be hashing your passwords. Never ever store plain text passwords. Since how exactly to hash passwords is a matter of much debate and would complicate the code, I’ll set this aside for now.

    Now, moving on to the actual question. First, there’s a few mistakes in the code. First is the parameters are being created wrong, what you have should be more along the lines of this:

    using(SqlConnection conn = new SqlConnection("connection string"))
    {
        SqlCommand cmd = new SqlCommand("Select * FROM Register where username=@username and password=@password", conn);
        cmd.Parameters.AddWithValue("@username", textbox1User.Text);
        cmd.Parameters.AddWithValue("@password", textbox2User.Text);
    }
    

    (see http://msdn.microsoft.com/en-us/library/yh598w02.aspx for more about using. It’s a good habit to get into)

    With that done, to easily validate the login, you can do something like this for your SqlCommand:

    SELECT COUNT(*) FROM Register WHERE username=@username AND password=@password
    

    And then add this to your code, after adding the parameters, but before the closing brace on the using:

    conn.Open();    
    int result = Convert.ToInt32(cmd.ExecuteScalar());
    

    result will be 0 if no user was found, or 1 if exactly one user was found (If you can have multiple users with the same user name, there are other issues outside of this scope).

    Now, as for enforcing access control take a look at http://support.microsoft.com/kb/301240 The terms you are interested in for this is “Forms Authentication” and “web.config authorization”. Please note that the code samples in the link provided are a bit outdated, but, in general, show how to accomplish what you are asking.

    That should get you started down the right track.

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

Sidebar

Related Questions

Okay, so I want to make a simple login page. I've created a register
I want to make an very simple chatting page no login required no sql
All I want is to make a simple user password login. I have put
This is login page: http://ts14.travian.com.sa/nachrichten.php I want the program to post the username and
I want to make a simple game: 2d, single-player, without tons of animations and
I want to make a application for customers. It should contain : 1.Login page
Basically I want to make simple toggle program (that will be mapped to some
I need information about making installation packages for Linux. I want to make simple
I want to make a simple app, where a UIWebView with custom content will
I want to make a simple game so that I can play against my

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.