nnnn
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
package com.ruoyi.cai.service.impl;
|
||||
|
||||
import cn.dev33.satoken.secure.BCrypt;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cai.domain.LoginAuth;
|
||||
import com.ruoyi.cai.domain.User;
|
||||
import com.ruoyi.cai.mapper.LoginAuthMapper;
|
||||
import com.ruoyi.cai.service.LoginAuthService;
|
||||
import com.ruoyi.cai.service.UserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class LoginAuthServiceImpl extends ServiceImpl<LoginAuthMapper,LoginAuth> implements LoginAuthService {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public void testLogin(List<String> passwords) {
|
||||
IPage<User> page = new Page<>();
|
||||
page.setSize(100);
|
||||
int current = 0;
|
||||
while (true){
|
||||
current++;
|
||||
page.setCurrent(current);
|
||||
IPage<User> userPAge = userService.page(page, Wrappers.<User>lambdaQuery().select(User::getId, User::getUsercode, User::getMobile));
|
||||
List<User> userList = userPAge.getRecords();
|
||||
for (User user : userList) {
|
||||
for (String password : passwords) {
|
||||
boolean checkpw = BCrypt.checkpw(password, user.getPassword());
|
||||
if(checkpw){ // 成功
|
||||
this.saveOrUpdate(user,password);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(userList.isEmpty()){
|
||||
break;
|
||||
}
|
||||
if(userList.size() < 100){
|
||||
break;
|
||||
}
|
||||
if(current > 10000){
|
||||
break;
|
||||
}
|
||||
}
|
||||
log.info("密码检测完毕");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkPassword(String mobile, String password){
|
||||
User user = userService.getByUsername(mobile);
|
||||
return BCrypt.checkpw(password, user.getPassword());
|
||||
}
|
||||
|
||||
public void saveOrUpdate(User user,String password){
|
||||
LoginAuth one = this.getOne(Wrappers.lambdaQuery(LoginAuth.class).eq(LoginAuth::getUserId, user.getId()).last("limit 1"));
|
||||
if(one != null){
|
||||
LoginAuth update = new LoginAuth();
|
||||
update.setId(one.getId());
|
||||
update.setPassword(password);
|
||||
this.updateById(update);
|
||||
}else{
|
||||
LoginAuth loginAuth = new LoginAuth();
|
||||
loginAuth.setUserId(user.getId());
|
||||
loginAuth.setUsercode(user.getUsercode());
|
||||
loginAuth.setMobile(user.getMobile());
|
||||
loginAuth.setPassword(password);
|
||||
this.save(loginAuth);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user