zoukankan      html  css  js  c++  java
  • 登录失败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'
  • 相关阅读:
    DM数据库disql的使用 Disql disql 达梦数据库Disql
    移动端禁止蒙层下的页面滚动
    移动端如何自动适配px
    使用Vant做移动端对图片预览ImagePreview和List的理解
    uniapp中使用uView组件库
    h5使用vuephotopreview 做全屏预览
    jsonview的实现
    PC端自适应使用rem 移动端适配升级版
    axios解决跨域问题(vuecli3.0)
    vs code 配置git path
  • 原文地址:https://www.cnblogs.com/lztkdr/p/Login_ErrorTimes.html
Copyright © 2011-2022 走看看