典型的asp.net登陆验证代码
2011-01-27 17:02
537 查看
void Page_Load(object sender, System.EventArgs e)
{
string username=Request.Form.Get("UserName");
string pwd=Request.Form.Get("PassWord");
ConnectSql(username,pwd);
}
private void ConnectSql(string username,string pwd)
{
IDbConnection conn = null;
try
{
conn = new SqlConnection("server=192.168.0.220;uid=sa;pwd=;database=text");
conn.Open();
string mySel="select * from [user] where name="+"'"+username+"'";
SqlCommand com = new SqlCommand(mySel, (SqlConnection)conn);
SqlDataReader reader = com.ExecuteReader();
if(!reader.HasRows)
{
Response.Redirect("index.aspx?error=用户名错误");
}
else
{
while(reader.Read())
{
if(pwd!=reader.GetString(2))
Response.Redirect("index.aspx?error=密码错误");
else
Response.Redirect("Main.html");
}
}
}
catch(SqlException)
{
Response.Write("在打开连接时出现连接级别的错误!");
}
finally
{
if(conn != null)
conn.Close();
}
{
string username=Request.Form.Get("UserName");
string pwd=Request.Form.Get("PassWord");
ConnectSql(username,pwd);
}
private void ConnectSql(string username,string pwd)
{
IDbConnection conn = null;
try
{
conn = new SqlConnection("server=192.168.0.220;uid=sa;pwd=;database=text");
conn.Open();
string mySel="select * from [user] where name="+"'"+username+"'";
SqlCommand com = new SqlCommand(mySel, (SqlConnection)conn);
SqlDataReader reader = com.ExecuteReader();
if(!reader.HasRows)
{
Response.Redirect("index.aspx?error=用户名错误");
}
else
{
while(reader.Read())
{
if(pwd!=reader.GetString(2))
Response.Redirect("index.aspx?error=密码错误");
else
Response.Redirect("Main.html");
}
}
}
catch(SqlException)
{
Response.Write("在打开连接时出现连接级别的错误!");
}
finally
{
if(conn != null)
conn.Close();
}
相关文章推荐
- asp.net利用jquery的ajax方法来验证登陆的代码
- ASP.net Logion用户登陆验证代码
- ASP.net Logion用户登陆验证代码
- ASP.net Logion用户登陆验证代码
- ASP.NET 图片验证码登陆代码
- ASP.net Logion用户登陆验证代码
- ASP.net Logion用户登陆验证代码
- ASP.net Logion用户登陆验证代码
- 看不懂:asp.net网站登陆图片验证代码
- ASP.net Logion用户登陆验证代码
- ASP.net Logion用户登陆验证代码
- ASP.NET中常用功能代码总结(2)——生成验证图片
- ASP.Net 2.0 窗体身份验证机制-转+自己代码注释示例与更详细的说明
- ASP.NET MVC 学习5、登陆页面改为SSO验证
- ASP.NET中服务器控件Button调用javascript代码运用正则表达式验证TextBox中输入的是否为正整数或正小数,符合要求则继续运行服务器端代码功能的实现
- asp.net验证提示美化效果代码(打包下载)
- asp.net一个简单的登陆系统代码
- ASP.NET 2.0 二级域名Forms验证模式下共享登陆状态
- asp.net 集成QQ2.0 登陆代码示例
- Ajax即时实现服务端数据验证(Asp.net 2.0)(示例代码下载)