加密密码测试类
This commit is contained in:
parent
6b6664763f
commit
c6ee408376
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue