问题描述
怎么利用单选框在登录判断是用户名还是身份证的代码。急急急!
解决方案
解决方案二:
前台radiobutton设置2个不同的值,后台取出radiobutton的选中值,比对,做判断
解决方案三:
用正则表达式~
解决方案四:
StringstrSQL="SELECT*FROM表名wherepassword=@password";if(this.CBUserName.Checked){//用户名被选中strSQL+="andusername=@value";}else{strSQL+="andidno=@value";}
解决方案五:
引用1楼wamlko的回复:
前台radiobutton设置2个不同的值,后台取出radiobutton的选中值,比对,做判断
if(RadioButton_Uid.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwhereuid='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["uid"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}elseif(RadioButton_IdCard.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["contacts_idcard"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}这样对吗?
解决方案六:
引用1楼wamlko的回复:
前台radiobutton设置2个不同的值,后台取出radiobutton的选中值,比对,做判断
就是这样的
解决方案七:
引用4楼zheng_09721的回复:
Quote: 引用1楼wamlko的回复:
前台radiobutton设置2个不同的值,后台取出radiobutton的选中值,比对,做判断if(RadioButton_Uid.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwhereuid='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["uid"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}elseif(RadioButton_IdCard.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["contacts_idcard"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}这样对吗?
首先这两个radiobutton要绑定在一个组里面,然后就是你这个方式了,顺便说一句,你这个代码人家用SQL注入攻击你就挂了
解决方案八:
在aspx中设置RadioButton1,想要单选效果,必须把GroupName设置成一样的。不然跟多选没区别。在后台再设置Button1_Click事件。
解决方案九:
引用4楼zheng_09721的回复:
Quote: 引用1楼wamlko的回复:
前台radiobutton设置2个不同的值,后台取出radiobutton的选中值,比对,做判断if(RadioButton_Uid.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwhereuid='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["uid"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}elseif(RadioButton_IdCard.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["contacts_idcard"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}这样对吗?
SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){if(RadioButton_Uid.Checked==true){Session["contacts_idcard"]=TextBox_Uid.Text;}else{Session["pwd"]=TextBox_Pwd.Text;}Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");这样是不是更好?
解决方案十:
SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){if(RadioButton_Uid.Checked==true){Session["uid"]=TextBox_Uid.Text;}else{Session["contacts_idcard"]=TextBox_Uid.Text;}Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");
解决方案十一:
引用6楼showyusy的回复:
Quote: 引用4楼zheng_09721的回复:
Quote: 引用1楼wamlko的回复:
前台radiobutton设置2个不同的值,后台取出radiobutton的选中值,比对,做判断if(RadioButton_Uid.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwhereuid='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["uid"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}elseif(RadioButton_IdCard.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["contacts_idcard"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}这样对吗?
首先这两个radiobutton要绑定在一个组里面,然后就是你这个方式了,顺便说一句,你这个代码人家用SQL注入攻击你就挂了
SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){if(RadioButton_Uid.Checked==true){Session["uid"]=TextBox_Uid.Text;}else{Session["contacts_idcard"]=TextBox_Uid.Text;}Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");这样会不会挂
解决方案十二:
引用10楼zheng_09721的回复:
Quote: 引用6楼showyusy的回复:
Quote: 引用4楼zheng_09721的回复:
Quote: 引用1楼wamlko的回复:
前台radiobutton设置2个不同的值,后台取出radiobutton的选中值,比对,做判断if(RadioButton_Uid.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwhereuid='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["uid"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}elseif(RadioButton_IdCard.Checked==true){SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){Session["contacts_idcard"]=TextBox_Uid.Text;Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");}else{Label1.Text="用户名或密码错误,请重新输入!";}}这样对吗?
首先这两个radiobutton要绑定在一个组里面,然后就是你这个方式了,顺便说一句,你这个代码人家用SQL注入攻击你就挂了
SqlConnectioncn=newSqlConnection("DataSource=.;InitialCatalog=zyz;IntegratedSecurity=True");cn.Open();SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);SqlDataAdapteradapter=newSqlDataAdapter(cmd);DataSetds=newDataSet();adapter.Fill(ds,"cc");cn.Close();if(ds.Tables["cc"].Rows.Count==1){if(RadioButton_Uid.Checked==true){Session["uid"]=TextBox_Uid.Text;}else{Session["contacts_idcard"]=TextBox_Uid.Text;}Session["pwd"]=TextBox_Pwd.Text;Session["org_user"]="cg";Response.Redirect("ActivityList.aspx");这样会不会挂
一样的,人家一旦发动SQL注入攻击你就挂了。SqlCommandcmd=newSqlCommand("select*fromorg_userwherecontacts_idcard='"+TextBox_Uid.Text+"'andpwd='"+TextBox_Pwd.Text+"'",cn);这一句里面的TextBox_Uid.Text和TextBox_Pwd.Text就是攻击源,你把文本框里面的东西直接给发往数据库查询了,人家在那里面写攻击代码你就挂了。
解决方案十三:
不用RadioButton就可以,后台用正则表达式判断。现在好多网站网站登录用户名一栏都是即可以输入邮箱又可输入手机号、昵称之类的,人家也没用RadioButton啊。这里就该正则表达式发威了...........
解决方案十四:
全服务器端控件,有必要这么纠结么。