Click here to Skip to main content
15,886,095 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
C#
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class login1 : System.Web.UI.Page
{
    
        Class1 obj = new Class1();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        

        DataSet ds = new DataSet();
        string qstr = "select * from login where UserName='" + TextBox1.Text + "'and password='" + TextBox2.Text + "'";
        obj.FillDs(qstr, ds);
        if (ds.Tables[0].Rows.Count == 1)
        {
            var un = TextBox1.Text;
            Response.Redirect("welcome.aspx?s="+un+"");
        }
        else
        {
            Label1.Text = "not valid user";
        }
    }
    }
Posted
Updated 13-Apr-11 18:40pm
v2
Comments
Pong D. Panda 14-Apr-11 0:43am    
What's the question here? What implementation?
Prerak Patel 14-Apr-11 0:43am    
Do you think the code is relevant? Moreover, using such a query for login is bad programming. Google 'SQL injection' to know more.
Pong D. Panda 14-Apr-11 0:54am    
You got him right on the spot. Try to put this on your TextBox1.Text as your username and it will work like magic! ';DROP TABLE login--

you can use session like this Session["username"]=TextBox.Text and retrive it like string username=Session["username"].ToString().
 
Share this answer
 
Session["User"]=TxtUser.text;
Session["ID"]=ID;
Response.Redirect("Home.aspx");
 
Share this answer
 
Do you mean like this as in below code??

C#
if (ds.Tables[0].Rows.Count == 1)
{
      var un = TextBox1.Text;
      Session["UserName"] = TextBox1.Text;
      Session["Password"] = TextBox2.Text;
      Response.Redirect("welcome.aspx?s="+un+"");
}
 
Share this answer
 
Comments
Wild-Programmer 14-Apr-11 2:15am    
Why vote me 1, whats wrong with my code??? :(
Ali Al Omairi(Abu AlHassan) 14-Apr-11 3:36am    
I dont think saving password in session is a good idea. and replace var with string.
+5
Wild-Programmer 14-Apr-11 6:27am    
I agree, but OP asked question about session handling, in hurry I stored the password too :D
Sorry about that.
Ali Al Omairi(Abu AlHassan) 14-Apr-11 6:37am    
you kow my friend, if you don't be not careful you wort survive here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900