用戶登陸。防SQL注入,驗證碼不區分大小寫。。
2008-03-15 14:13
204 查看
if (string.Compare(TBCheckCode.Text, Session["CheckCodeI"].ToString(), true) == 0)
{
string password = FormsAuthentication.HashPasswordForStoringInConfigFile(TBpassword.Text, "md5");//MD5加密
string mycon = ConfigurationManager.ConnectionStrings["EPS_WEBConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(mycon);
con.Open();
SqlParameter tetusername = new SqlParameter("@username", SqlDbType.Char, 30);
tetusername.Value = TBusername.Text;
SqlParameter tetpassword = new SqlParameter("@userpass", SqlDbType.Char, 40);
tetpassword.Value = password;
string strsql = "select * from admin_user where UserName=@username and Password=@userpass";
SqlCommand mycommand = new SqlCommand(strsql, con);
mycommand.Parameters.Add(tetusername);
mycommand.Parameters.Add(tetpassword);
SqlDataReader rs = mycommand.ExecuteReader();
if (rs.Read())
{
if (password == rs["Password"].ToString())
{
Session.Timeout = 120;
Session["UserName"] = TBusername.Text;
Session["UserID"] = rs["ID"].ToString();
con.Close();
Response.Redirect("index.htm");
// Response.Write("<script >window.open('index.htm');</script>");
}
else
{
con.Close();
Label1.Visible = true;
Label1.Text = "对不起,您输入的密码有误!";
return;
}
}
else
{
con.Close();
Label1.Visible = true;
Label1.Text = "对不起,帐号或密码错误!";
return;
}
}
else
{
Label1.Visible = true;
Label1.Text = "对不起,驗證碼錯誤!";
return;
}
{
string password = FormsAuthentication.HashPasswordForStoringInConfigFile(TBpassword.Text, "md5");//MD5加密
string mycon = ConfigurationManager.ConnectionStrings["EPS_WEBConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(mycon);
con.Open();
SqlParameter tetusername = new SqlParameter("@username", SqlDbType.Char, 30);
tetusername.Value = TBusername.Text;
SqlParameter tetpassword = new SqlParameter("@userpass", SqlDbType.Char, 40);
tetpassword.Value = password;
string strsql = "select * from admin_user where UserName=@username and Password=@userpass";
SqlCommand mycommand = new SqlCommand(strsql, con);
mycommand.Parameters.Add(tetusername);
mycommand.Parameters.Add(tetpassword);
SqlDataReader rs = mycommand.ExecuteReader();
if (rs.Read())
{
if (password == rs["Password"].ToString())
{
Session.Timeout = 120;
Session["UserName"] = TBusername.Text;
Session["UserID"] = rs["ID"].ToString();
con.Close();
Response.Redirect("index.htm");
// Response.Write("<script >window.open('index.htm');</script>");
}
else
{
con.Close();
Label1.Visible = true;
Label1.Text = "对不起,您输入的密码有误!";
return;
}
}
else
{
con.Close();
Label1.Visible = true;
Label1.Text = "对不起,帐号或密码错误!";
return;
}
}
else
{
Label1.Visible = true;
Label1.Text = "对不起,驗證碼錯誤!";
return;
}
相关文章推荐
- 用戶登陸。防SQL注入,驗證碼不區分大小寫
- 用戶登陸。防SQL注入,驗證碼不區分大小寫。。
- SQL中的條件式區分大小寫
- 從登陸名與用戶名的區別說起,談SQL Server安全性初步
- SQL 查詢不區分大小寫
- VS2012使用验证控件出现[ASP.NET]WebForms UnobtrusiveValidationMode 需要 'jquery' 的 ScriptResourceMapping。請加入 ScriptResourceMapping 命名的 jquery (區分大小寫)。的解决办法。
- 用戶登陸驗證
- java比较日期大小
- struts2 修改默认上传大小
- Android PopupWindow显示位置和显示大小
- bash新手if语句实现三个数比较大小
- 【转自】限制Apache日志文件大小的方法
- 扩表空间的大小参考最大扩多大
- android 一个 textview 设置不同的字体大小和颜色
- swift---不同字体大小不同颜色label富文本设置
- 不用比较运算符,判断int型的a,b两数的大小。
- struts2上传图片后程序自动给缩图到固定大小
- Linux 通过lseek()来实现文件大小的设置
- 12 获取外部存储卡大小
- Crystal reports 默认纸张大小