Ver Fonte

弱密码检测

xiongzhu há 4 anos atrás
pai
commit
9e6723c982

+ 6 - 1
src/main/java/com/izouma/nineth/service/UserService.java

@@ -44,6 +44,7 @@ import org.springframework.core.env.Environment;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.scheduling.annotation.Async;
@@ -51,7 +52,10 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
@@ -741,7 +745,8 @@ public class UserService {
         int pageNum = 0;
         List<User> list = new ArrayList<>();
         while (hasNext) {
-            Page<User> page = userRepo.findAll(PageRequest.of(pageNum++, 200));
+            Page<User> page = userRepo.findAll((Specification<User>) (root, query, criteriaBuilder) ->
+                    criteriaBuilder.isNotNull(root.get("password")), PageRequest.of(pageNum++, 200, Sort.by("id")));
             page.getContent().parallelStream().forEach(user -> {
                 BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
                 boolean match = false;