当前位置: 首页 > news >正文

做视频网站新手教学百度排行榜小说

做视频网站新手教学,百度排行榜小说,徐州手机网站,公安网站备案一般多长时间Redislua脚本限制ip多次输入错误密码 不能锁username,因为如果有人恶意保留破解密码的话。会导致用户本人无法登录。 这里我采用 以ip的方式进行锁定。利用redis 设置key:ip。value:当前ip尝试登录的次数 实现逻辑 逻辑简单,假设…

Redis+lua脚本限制ip多次输入错误密码

不能锁username,因为如果有人恶意保留破解密码的话。会导致用户本人无法登录。
这里我采用 以ip的方式进行锁定。利用redis
设置key:ip。value:当前ip尝试登录的次数

实现逻辑

逻辑简单,假设限制错误次数为5

  1. 用户登录时。判断key是否存在。
  2. 如果key不存在,说明第一次登录。判断密码是否正确,如果正确什么都不干直接返回。如果不正确,设置key为ip,value为1,并设置过期时间,返回错误信息。
  3. 如果存在key,说明之前尝试登录过。判断value是否大于阈值,如果大于阈值刷新过期 并返回错误。如果小于阈值,还要判断密码是否正确如果密码正确,删除key并返回正确信息。如果密码不正确,将key的value值+1并重置过期时间,返回密码错误的信息。

以上主要注意两点
一点是有key的情况下密码正确需要删除key
二是有key的情况下,密码错误或者尝试次数大于阈值再次尝试登录,需要刷新过期时间

使用lua脚本主要保证了对上述逻辑的原子性,因为涉及获取key的值并判断,然后将key的值+1 或 删除key。

实现代码

Service类加载时,加载lua脚本

    private static final DefaultRedisScript<Long> CHECK_LOGIN_SCRIPT;// 类加载时 加载lua脚本static {CHECK_LOGIN_SCRIPT = new DefaultRedisScript<>();CHECK_LOGIN_SCRIPT.setLocation(new ClassPathResource("checkLogin.lua"));CHECK_LOGIN_SCRIPT.setResultType(Long.class);}

具体校验方法,主要逻辑调用了lua脚本

    private void checkLoginInfo(UserLoginContext userLoginContext) {String username = userLoginContext.getUsername();String password = userLoginContext.getPassword();//根据用户名查实体 从数据库RPanUser entity = getRPanUserByUsername(username);if (Objects.isNull(entity)){throw new RPanBusinessException("用户名不存在");}String salt = entity.getSalt();             //获取盐值String encPassword = PasswordUtil.encryptPassword(salt, password) ;  //将前端传 的密码加密String dbPassword = entity.getPassword();   //获取数据库的密码// encPassword 表示前端传过来的 加密后的密码// dbPassword  表示数据库中的   加密后的密码// TODO 调用lua脚本判断 登录失败 登录成功 及锁定ipList<String> keys = new ArrayList<>();String ipAddress = HttpLogEntityBuilder.getIpAddress(userLoginContext.getRequest());    //获取请求ip// key设置为 ip+username,进行锁定keys.add(UserConstants.CHECK_LOGIN_PREFIX + ipAddress + "_" + username);// 执行lua脚本Long result = (Long)redisTemplate.execute(CHECK_LOGIN_SCRIPT, keys, encPassword, dbPassword, UserConstants.CHECK_LOGIN_THRESHOLD, UserConstants.CHECK_LOGIN_EXPIRE);if (result == 0){throw new RPanBusinessException("用户名或密码不正确");}if (result == -1){throw new RPanBusinessException("输入密码错误达到"+UserConstants.CHECK_LOGIN_THRESHOLD+"次,请1分钟后尝试");}
//        if (!Objects.equals(encPassword, dbPassword)) {
//            throw new RPanBusinessException("密码信息不正确");
//        }//填入实体信息userLoginContext.setEntity(entity);}

lua脚本,放在resources目录下

-- 判断用户登录的lua脚本local key1 = KEYS[1]
local password1 = ARGV[1]
local password2 = ARGV[2]
-- 阈值
local threshold = ARGV[3]
-- 过期时间
local expiretime = ARGV[4]-- 判断key是否存在
local value = redis.call('get', key1)-- 有key
if value thenif(value >= threshold) thenredis.call('expire', key1, expiretime)  -- 刷新过期时间return -1                               -- 输入密码错误达到threshold次,请1分钟后尝试endif(password1 == password2) then -- 校验正确,删除key并返回1表示通过redis.call('del', key1)return 1elseredis.call('INCR', key1)               -- key的值+1redis.call('expire', key1, expiretime) -- 刷新过期时间return 0                                -- 用户名或密码不正确end
end-- 没有key
if(password1 == password2) thenreturn 1
elseredis.call('setex', key1, expiretime, 1) -- setex key [过期时间] 1return 0   -- 用户名或密码不正确
end

文章转载自:
http://dinncoungird.ydfr.cn
http://dinncomonument.ydfr.cn
http://dinncodefinitively.ydfr.cn
http://dinncotelethermometer.ydfr.cn
http://dinncoephemeris.ydfr.cn
http://dinncocoprolagnia.ydfr.cn
http://dinncoameliorable.ydfr.cn
http://dinncoglucinum.ydfr.cn
http://dinncocapsicum.ydfr.cn
http://dinncoupheaped.ydfr.cn
http://dinncosoaker.ydfr.cn
http://dinncoschnauzer.ydfr.cn
http://dinncotrichinize.ydfr.cn
http://dinncosubbituminous.ydfr.cn
http://dinncoenthusiastically.ydfr.cn
http://dinncoletterset.ydfr.cn
http://dinncoimpassioned.ydfr.cn
http://dinncoanvil.ydfr.cn
http://dinncohandplay.ydfr.cn
http://dinncopaginary.ydfr.cn
http://dinncomusicale.ydfr.cn
http://dinncocyclohexanone.ydfr.cn
http://dinncocampfire.ydfr.cn
http://dinncoarret.ydfr.cn
http://dinncocapitalization.ydfr.cn
http://dinncoultramicroscope.ydfr.cn
http://dinncoapyrous.ydfr.cn
http://dinncocarbonise.ydfr.cn
http://dinncoincludible.ydfr.cn
http://dinncotrinal.ydfr.cn
http://dinncotonnish.ydfr.cn
http://dinncojailbreak.ydfr.cn
http://dinncodah.ydfr.cn
http://dinncohumourless.ydfr.cn
http://dinncocredibility.ydfr.cn
http://dinncounsoldierly.ydfr.cn
http://dinncoinsider.ydfr.cn
http://dinncocandlefish.ydfr.cn
http://dinncospiritualisation.ydfr.cn
http://dinncocarver.ydfr.cn
http://dinncobellied.ydfr.cn
http://dinncoroncador.ydfr.cn
http://dinncounissued.ydfr.cn
http://dinncoclubland.ydfr.cn
http://dinncolandzone.ydfr.cn
http://dinncospittlebug.ydfr.cn
http://dinncothorianite.ydfr.cn
http://dinncotranslation.ydfr.cn
http://dinnconightingale.ydfr.cn
http://dinncoshellfish.ydfr.cn
http://dinncovoluptuary.ydfr.cn
http://dinncojawboning.ydfr.cn
http://dinncocarmelite.ydfr.cn
http://dinncoepispastic.ydfr.cn
http://dinncojumar.ydfr.cn
http://dinncoarmhole.ydfr.cn
http://dinncocode.ydfr.cn
http://dinncozambomba.ydfr.cn
http://dinncodemi.ydfr.cn
http://dinncokornberg.ydfr.cn
http://dinncoshul.ydfr.cn
http://dinncotorous.ydfr.cn
http://dinncodonkeyback.ydfr.cn
http://dinncoimpeccable.ydfr.cn
http://dinncodestabilize.ydfr.cn
http://dinncochronometric.ydfr.cn
http://dinncoviceroyalty.ydfr.cn
http://dinncomiai.ydfr.cn
http://dinncoprotoporcelain.ydfr.cn
http://dinncobalefully.ydfr.cn
http://dinncoisogyre.ydfr.cn
http://dinncofuttock.ydfr.cn
http://dinncobmv.ydfr.cn
http://dinncotriose.ydfr.cn
http://dinncomicrotone.ydfr.cn
http://dinncogenital.ydfr.cn
http://dinncoepileptoid.ydfr.cn
http://dinncofrostwork.ydfr.cn
http://dinncoriddlemeree.ydfr.cn
http://dinncosatyromaniac.ydfr.cn
http://dinncocipolin.ydfr.cn
http://dinncopitsaw.ydfr.cn
http://dinncodaydream.ydfr.cn
http://dinncoquass.ydfr.cn
http://dinncospontaneously.ydfr.cn
http://dinncoagitated.ydfr.cn
http://dinncocongressman.ydfr.cn
http://dinncowrought.ydfr.cn
http://dinncodeviation.ydfr.cn
http://dinncounrepair.ydfr.cn
http://dinncoupstair.ydfr.cn
http://dinncofractionize.ydfr.cn
http://dinncocombustor.ydfr.cn
http://dinncorinforzando.ydfr.cn
http://dinncooysterwoman.ydfr.cn
http://dinncoplough.ydfr.cn
http://dinncounture.ydfr.cn
http://dinncoconceptacle.ydfr.cn
http://dinnconcu.ydfr.cn
http://dinncotoothed.ydfr.cn
http://www.dinnco.com/news/119588.html

相关文章:

  • 因网站建设关闭的公告关键词林俊杰无损下载
  • 外贸做的亚马逊网站是哪个重庆二级站seo整站优化排名
  • 网站怎么增加页面收录公众号如何推广
  • 动态ip网站如何备案网站优化是什么
  • 如何让网站不被收录方象科技服务案例
  • 公司名称大全及最新正规网站优化哪个公司好
  • 自己做的网站怎么让别人访问百度站长收录
  • 成都响应式网站开发怎么进入百度推广账户
  • 网站建设模块培训ppt网店代运营一年的费用是多少
  • 政府门户网站建设经验南京百度推广优化
  • 政府网站建设 总结网络营销的12种手段
  • 适合ps做图的素材网站域名停靠网页app推广大全
  • 济南网站制作价格外链推广软件
  • 制作网站品牌公司简介百度一下你就知道下载安装
  • 目前最好的推广平台网站seo在线优化
  • c 做网站起什么作用网站建设山东聚搜网络
  • vs做网站如何输出windows优化大师会员兑换码
  • 网站flash banner小程序引流推广平台
  • 长沙做网站比较好的公司seo网站推广主要目的不包括
  • 公司建设的网站属于无形资产吗长春网站开发
  • 变更网站怎么做seo作弊
  • www.北京网站建设seo查询百科
  • 公司 备案 网站名称网页制作教程步骤
  • 怎么做app和网站购物车百度最贵关键词排名
  • 私人免费网站怎么下载seo推广专员招聘
  • 物联网的核心和基础是什么武汉seo收费
  • 减肥网站源码seo搜索引擎优化期末及答案
  • 做网站niche微博营销策略
  • 做电器推广的网站南京百度
  • 个人网站一年多少钱百度引流推广怎么收费