<table class="style1"> <tr> <td class="style2"> <asp:Label ID="Label1" runat="server" Text="USERNAME"></asp:Label> </td> <td class="style3"> <asp:TextBox ID="txtUserName" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="18px" Width="127px"></asp:TextBox> </td> </tr> <tr> <td class="style2"> <asp:Label ID="Label2" runat="server" Text="PASSWORD"></asp:Label> </td> <td class="style3"> <asp:TextBox ID="txtPassword" runat="server" BorderStyle="Solid" BorderWidth="1px" Height="18px" TextMode="Password" Width="127px"></asp:TextBox> </td> </tr> <tr> <td colspan="2" style="text-align: center"> <asp:Button ID="btnLogin" runat="server" Text="Login" BackColor="White" BorderStyle="Solid" BorderWidth="1px" onclick="btnLogin_Click" /> </td> </tr> <tr> <td colspan="2" style="text-align: center"> <asp:Label ID="lbStatus" runat="server"></asp:Label></td> </tr> </table>
protected void btnLogin_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"; SqlCommand cmd = new SqlCommand(); con.Open(); cmd.CommandText = @"SELECT USERNAME FROM USERS_TABLE WHERE USERNAME='"+txtUserName.Text+"' AND PASSWORD='"+txtPassword.Text+"'"; cmd.Connection = con; object o = cmd.ExecuteScalar(); if (o == null) { lbStatus.Text = "Invalid login"; return; } Session["username"] = o; lbStatus.Text = "Success"; con.Close(); }
Hall of Fame Twitter Terms of Service Privacy Policy Contact Us Archives Tell A Friend