How to check your password and id match or not in Database



  • source :


 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
        password&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="login" />
    
    </div>
    </form>
</body>
</html>


default.aspx.cs 

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand com;
    SqlDataAdapter da;
    DataTable dt;
    string str;
    protected void Page_Load(object sender, EventArgs e)
    {
        str = @"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\alex\Documents\Visual Studio 2010\WebSites\passandid\App_Data\Database.mdf;Integrated Security=True;User Instance=True";
        con = new SqlConnection(str);
        con.Open();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        com = new SqlCommand("select * from data where id='"+TextBox1.Text+"' and password='"+TextBox2.Text+"'",con);
        com.ExecuteNonQuery();
        da = new SqlDataAdapter(com);
        dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count == 1)
        {
            Response.Write("id and password match");
        }
        else
        {
            Response.Write("id and password not match");
        }

        

    }
}

Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

Calendar in Asp.net

CheckBox in Asp.Net MVC (Insert Data of CheckBox in Database and GetData Of checkBox From DataBase)