Commit e8dcd3a6 authored by renjie's avatar renjie

用户加密密码

parent c4199812
...@@ -691,7 +691,7 @@ public class AccountServiceImpl implements AccountService { ...@@ -691,7 +691,7 @@ public class AccountServiceImpl implements AccountService {
} }
public static String makeRandomPassword(int len){ public static String makeRandomPassword(int len){
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@$%^&*.?".toCharArray(); char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Random r = new Random(); Random r = new Random();
for (int x = 0; x < len; ++x) { for (int x = 0; x < len; ++x) {
...@@ -734,9 +734,8 @@ public class AccountServiceImpl implements AccountService { ...@@ -734,9 +734,8 @@ public class AccountServiceImpl implements AccountService {
User authUser = new User(); User authUser = new User();
authUser.setUsername(user.getName()); authUser.setUsername(user.getName());
String password; String password;
if (org.apache.commons.lang3.StringUtils.isNotBlank(subUsersRequestDto.getPassword())) { if (org.apache.commons.lang3.StringUtils.isNotBlank(subUsersRequestDto.getPassword()))
password = Aes.aesDecrypt(subUsersRequestDto.getPassword()); password = Aes.aesDecrypt(subUsersRequestDto.getPassword());
}
else else
password = makeRandomPassword(8); password = makeRandomPassword(8);
...@@ -763,8 +762,8 @@ public class AccountServiceImpl implements AccountService { ...@@ -763,8 +762,8 @@ public class AccountServiceImpl implements AccountService {
if (user.getWhiteList() != null && user.getWhiteList().size() > 0) if (user.getWhiteList() != null && user.getWhiteList().size() > 0)
whiteList.addAll(user.getWhiteList()); whiteList.addAll(user.getWhiteList());
account.setWhiteList(whiteList); account.setWhiteList(whiteList);
password = Aes.aesEncrypt(password); String newpassword = Aes.aesEncrypt(password);
account.setPassword(password); account.setPassword(newpassword);
repository.save(account); repository.save(account);
// emailService.sendEmailVerification(user.getUsername(), user.getEmail(), user.getVerificationCode()); // emailService.sendEmailVerification(user.getUsername(), user.getEmail(), user.getVerificationCode());
......
...@@ -153,12 +153,12 @@ public class Aes { ...@@ -153,12 +153,12 @@ public class Aes {
* 测试 * 测试
*/ */
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
String content = "123"; String content = "VHRg3tocHf9i2Q27COKDhw==";
System.out.println("加密前:" + content); // System.out.println("加密前:" + content);
System.out.println("加密密钥和解密密钥:" + KEY); // System.out.println("加密密钥和解密密钥:" + KEY);
String encrypt = aesEncrypt(content, KEY); // String encrypt = aesEncrypt(content, KEY);
System.out.println("加密后:" + encrypt); // System.out.println("加密后:" + encrypt);
String decrypt = aesDecrypt(encrypt, KEY); String decrypt = aesDecrypt(content, KEY);
System.out.println("解密后:" + decrypt); System.out.println("解密后:" + decrypt);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment