登录失败3次验证码校验

--开发背景: 当对客户端访问时,分机器访问和人工访问,为遏制机器登录攻击,建立验证码错误3次,针对IP地址一天之内登录失败3次,则对其需要增加验证码的校验。
-- 为不用每次都记录一条错误登录的时间记录,使用存储过程。

--submit 登录失败,更新存储过程

--页面刷新,查询错误次数,然后程序设置显示验证码。

--提示:虽然有效机器人登录,但是验证码的识别技术 早已经公开,防止攻击的 有效手段还需加强。

    --针对登录失败,记录针对IP地址的登录失败记录表
            create table LoginRecords
            (
               LoginId  uniqueidentifier primary key default(newid()), -- GUID 类型,自动生成
               IP_Address varchar(200),                                

   -- 客户端IP地址
               LoginTime datetime default(getdate()),                   -- 上次登

录失败的时间
               ErrorTimes int default(0)                               

-- 错误次数
            )


            ---更新错误次数存储过程 

            create proc [usp_GetErrorTimes]
            @ip_address varchar(200)
            as 
            declare @lastTime datetime
            select @lastTime=LoginTime from LoginRecords where IP_Address=@ip_address  
            if(@lastTime is null)
            begin
               insert into LoginRecords(IP_Address,ErrorTimes)values(@ip_address,1);
            end 
            else
            begin

                if(DATEDIFF(day,@lastTime,getdate())>1)  -- 上次登录错误的时间与当前登录错误的时

间 相减 > 1begin
                        update LoginRecords set ErrorTimes=1,LoginTime=GETDATE()  --

重新计数
                         where IP_Address=@ip_address
                    end
                else
                    begin
                        update LoginRecords set ErrorTimes=ErrorTimes

+1,LoginTime=GETDATE() --累加错误次数
                         where IP_Address=@ip_address                 
                    end
            end


        --  exec usp_GetErrorTimes '192.168.1.152'

 

转载于:https://www.cnblogs.com/lztkdr/archive/2013/04/26/Login_ErrorTimes.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值