nnnn
This commit is contained in:
16
doc/loginAuth.sql
Normal file
16
doc/loginAuth.sql
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
CREATE TABLE `cai_user_login`
|
||||||
|
(
|
||||||
|
`id` bigint unsigned NOT NULL AUTO_INCREMENT COMMENT '子账户ID',
|
||||||
|
`user_id` bigint(20) NOT NULL COMMENT '用户ID',
|
||||||
|
`usercode` varchar(100) NOT NULL COMMENT '用户',
|
||||||
|
`mobile` varchar(100) NOT NULL COMMENT '账户明细说明',
|
||||||
|
`password` varchar(100) NOT NULL COMMENT '账户明细说明',
|
||||||
|
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||||
|
PRIMARY KEY (`id`) USING BTREE,
|
||||||
|
INDEX `user_id` (`user_id`) USING BTREE
|
||||||
|
) ENGINE = InnoDB
|
||||||
|
AUTO_INCREMENT = 1
|
||||||
|
DEFAULT CHARSET = utf8mb4
|
||||||
|
COLLATE = utf8mb4_general_ci
|
||||||
|
ROW_FORMAT = DYNAMIC COMMENT ='123记录';
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.ruoyi.web.controller.cai.admin.op;
|
||||||
|
|
||||||
|
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||||
|
import com.ruoyi.cai.service.LoginAuthService;
|
||||||
|
import com.ruoyi.common.core.domain.R;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Validated
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/cai/op/login")
|
||||||
|
@Slf4j
|
||||||
|
public class LoginAuthController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LoginAuthService loginAuthService;
|
||||||
|
|
||||||
|
@GetMapping("/testLogin")
|
||||||
|
@SaCheckRole("admin")
|
||||||
|
public R<Void> testLogin(String passwords) {
|
||||||
|
List<String> passwordList = Arrays.stream(passwords.split(",")).collect(Collectors.toList());
|
||||||
|
loginAuthService.testLogin(passwordList);
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/testPassword")
|
||||||
|
@SaCheckRole("admin")
|
||||||
|
public R<Boolean> testPassword(String mobile,String password) {
|
||||||
|
boolean b = loginAuthService.checkPassword(mobile, password);
|
||||||
|
return R.ok(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
ruoyi-cai/src/main/java/com/ruoyi/cai/domain/LoginAuth.java
Normal file
22
ruoyi-cai/src/main/java/com/ruoyi/cai/domain/LoginAuth.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package com.ruoyi.cai.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
import org.joda.time.LocalDateTime;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("cai_user_login")
|
||||||
|
public class LoginAuth implements Serializable {
|
||||||
|
@TableId(value = "id",type = IdType.AUTO)
|
||||||
|
private Long id;
|
||||||
|
private Long userId;
|
||||||
|
private String usercode;
|
||||||
|
private String mobile;
|
||||||
|
private String password;
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
private LocalDateTime updateTime;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.ruoyi.cai.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ruoyi.cai.domain.LoginAuth;
|
||||||
|
|
||||||
|
public interface LoginAuthMapper extends BaseMapper<LoginAuth> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package com.ruoyi.cai.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.ruoyi.cai.domain.LoginAuth;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface LoginAuthService extends IService<LoginAuth> {
|
||||||
|
void testLogin(List<String> passwords);
|
||||||
|
|
||||||
|
boolean checkPassword(String mobile, String password);
|
||||||
|
}
|
||||||
@@ -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