加密密码测试类

This commit is contained in:
石皮幼鸟 2024-04-26 19:21:30 +08:00
parent 6b6664763f
commit c6ee408376
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
package com.example.catchTheLetters;
import com.example.catchTheLetters.entity.User;
import jakarta.annotation.Resource;
import com.example.catchTheLetters.utils.DESUtil;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
@SpringBootTest
public class PasswordChangeTest {
@Resource
private MongoTemplate mongoTemplate;
@Resource
private DESUtil desUtil;
@Disabled
@Test
void testChangePassword() {
// 查出所有用户
var users = mongoTemplate.findAll(User.class);
for (var user : users) {
// 对密码进行加密
var password = user.getPassword();
var newPassword = desUtil.SHA512(password);
user.setPassword(newPassword);
// 保存
mongoTemplate.save(user);
}
}
}