小牛他爹的专栏
登录
注册
全站
当前博客
空间
博客
好友
相册
留言
控制验证登陆次数
收藏
为了防止暴力破解 ,通常使用验证码,现在加入一种新的防暴力破解方法,限制验证登陆错误次数,并封锁IP
代码如下
/**/
///
<summary>
///
Login 的摘要说明。
///
</summary>
public
class
Login : System.Web.UI.Page
...
{
protected
System.Web.UI.WebControls.RequiredFieldValidator rfvUsername;
protected
System.Web.UI.WebControls.RequiredFieldValidator rfvPassword;
protected
System.Web.UI.WebControls.Label lblErrorMessage;
protected
System.Web.UI.WebControls.TextBox txtUserName;
protected
System.Web.UI.WebControls.TextBox txtPassWord;
protected
System.Web.UI.WebControls.TextBox txtYanzheng;
protected
System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator1;
protected
System.Web.UI.WebControls.ImageButton btnLogin;
protected
System.Web.UI.WebControls.Image Image1;
string
strIp
=
""
;
private
void
Page_Load(
object
sender, System.EventArgs e)
...
{
//
在此处放置用户代码以初始化页面
if
(
!
Page.IsPostBack)
...
{
Session[
"
CheckCode
"
]
=
""
;
}
}
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
override
protected
void
OnInit(EventArgs e)
...
{
//
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base
.OnInit(e);
}
/**/
///
<summary>
///
设计器支持所需的方法 - 不要使用代码编辑器修改
///
此方法的内容。
///
</summary>
private
void
InitializeComponent()
...
{
this
.btnLogin.Click
+=
new
System.Web.UI.ImageClickEventHandler(
this
.ImageButton2_Click);
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
private
void
ImageButton2_Click(
object
sender, System.Web.UI.ImageClickEventArgs e)
...
{
WebJTJ.Components.IPLock ip
=
new
WebJTJ.Components.IPLock();
bool
IPLocked
=
ip.IPLockCheck(GetIP());
if
(IPLocked)
...
{
lblErrorMessage.Text
=
"
您的ip地址已经被锁定,请联系管理员!
"
;
}
else
...
{
if
(Convert.ToInt16(Session[
"
LoginTimes
"
])
<
1
)
...
{
if
(txtYanzheng.Text.Trim()
==
Session[
"
CheckCode
"
].ToString())
...
{
string
UserID
=
""
;
WebJTJ.Components.Staff staff
=
new
WebJTJ.Components.Staff();
string
CheckString
=
staff.Login(txtUserName.Text, txtPassWord.Text);
if
(CheckString
!=
null
)
...
{
string
LoginChecked;
if
(CheckString.IndexOf(
"
-
"
)
>=
0
)
...
{
UserID
=
CheckString.Substring(
0
,CheckString.IndexOf(
"
-
"
));
LoginChecked
=
CheckString.Substring(CheckString.IndexOf(
"
-
"
)
+
1
);
if
(LoginChecked
==
"
True
"
)
...
{
Session[
"
UserName
"
]
=
txtUserName.Text;
Session[
"
UserID
"
]
=
UserID;
Session[
"
WebManager
"
]
=
LoginChecked;
Response.Redirect(
"
Admin_Main.aspx
"
);
}
}
}
else
...
{
Session[
"
LoginTimes
"
]
=
Convert.ToInt16(Session[
"
LoginTimes
"
])
+
1
;
lblErrorMessage.Text
=
"
您输入的用户名或密码错误,请重新输入!
"
;
}
}
else
...
{
lblErrorMessage.Text
=
"
您输入的验证码错误!请重新输入!
"
;
}
}
else
...
{
if
(Request.ServerVariables[
"
HTTP_VIA
"
]
!=
null
)
...
{
strIp
=
Request.ServerVariables[
"
HTTP_X_FORWARDED_FOR
"
].ToString();
}
else
...
{
strIp
=
Request.ServerVariables[
"
REMOTE_ADDR
"
].ToString();
}
if
(strIp.Length
>
0
)
...
{
WebJTJ.Components.Staff IPLock
=
new
WebJTJ.Components.Staff();
IPLock.IPLock(strIp);
}
lblErrorMessage.Text
=
"
对不起,您的密码输入次数已经收到限制,您的IP地址已经被记录封锁,请联系管理员给您解除锁定!
"
;
}
}
}
public
string
GetIP()
...
{
if
(Request.ServerVariables[
"
HTTP_VIA
"
]
!=
null
)
...
{
strIp
=
Request.ServerVariables[
"
HTTP_X_FORWARDED_FOR
"
].ToString();
}
else
...
{
strIp
=
Request.ServerVariables[
"
REMOTE_ADDR
"
].ToString();
}
return
strIp ;
}
}
}
发表于 @ 2007年05月26日 14:50:00|
评论(
loading...
)
|
举报
|
收藏
新一篇: 时间参数
|
旧一篇: asp.net +C# +sql2000 实现仿csdn的图片轮换代码
用户操作
[即时聊天]
[发私信]
[加为好友]
小牛他爹
订阅我的博客
文章分类
dotNet&C#
Java&Grails
收藏
存档
2009年04月(2)
2008年12月(1)
2007年11月(1)
2007年10月(1)
2007年08月(1)
2007年07月(1)
2007年06月(2)
2007年05月(4)
2004年05月(1)
软件项目交易