net教学之登录页面net教学之登录页面
效果图:
流程:
1、用户名和密码都正确时,转向welcome.aspx页面。 2、用户名正确,密码不正确,可以尝试三次,三次都错误,不允许登录。 3、用户名不正确,可以尝试三次,三次都错误,不允许登录。
关键代码:
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_reg_Click...
net教学之登录页面
效果图:
流程:
1、用户名和密码都正确时,转向welcome.aspx页面。 2、用户名正确,密码不正确,可以尝试三次,三次都错误,不允许登录。 3、用户名不正确,可以尝试三次,三次都错误,不允许登录。
关键代码:
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_reg_Click(object sender, EventArgs e)//注册按钮
{
Response.Redirect("reguser.aspx");
}
static int n, m;//静态变量,控制试错次数
protected void btn_login_Click(object sender, EventArgs e)//登录按钮
{
string constr = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
string sql1 = "select * from [user] where id='" + txb_id.Text.Trim() + "'";
string sql2 = "select * from [user] where pwd='" + txb_pwd.Text.Trim() + "' and id='"+txb_id.Text.Trim()+"'";
bool i, j;
SqlConnection con = new SqlConnection(constr);
try
{
con.Open();
SqlCommand com1 = new SqlCommand(sql1, con);
SqlCommand com2 = new SqlCommand(sql2, con);
SqlDataReader reader1 = com1.ExecuteReader();
i = reader1.HasRows;
reader1.Close();
SqlDataReader reader2 = com2.ExecuteReader();
j = reader2.HasRows;
reader2.Close();
if (i)
{
if (j)
{
Response.Redirect("welcome.aspx?id=" + txb_id.Text + "");//向welcome.aspx页面传递参数id
}
else
{
n = n + 1;
if (n < 3)
{
Response.Write("");
txb_pwd.Text = "";
}
else
{
Response.Write("");
txb_id.ReadOnly = true;
txb_pwd.ReadOnly = true;
}
}
}
else
{
m = m + 1;
if (m < 3)
{
Response.Write("");
txb_id.Text = "";
txb_pwd.Text = "";
}
else
{
Response.Write("");
txb_id.ReadOnly = true;
txb_pwd.ReadOnly = true;
}
}
}
catch (SqlException ex)
{
Response.Write("");
}
finally
{
con.Close();
}
}
}
本文档为【net教学之登录页面】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。