Skip to content

Commit

Permalink
Merge pull request #150 from chenhaozx/feature/modify-random-salt
Browse files Browse the repository at this point in the history
modify random salt generator
  • Loading branch information
chenhaozx committed Jun 19, 2019
2 parents cfb089c + f8bfe87 commit 2fc756f
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/main/java/com/webank/weid/util/DataToolUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
Expand Down Expand Up @@ -83,6 +82,7 @@
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.bcos.web3j.abi.datatypes.Address;
import org.bcos.web3j.abi.datatypes.DynamicArray;
Expand Down Expand Up @@ -126,6 +126,11 @@ public final class DataToolUtils {

private static final String FORMAT_NAME = "JPG";

/**
* default salt length.
*/
private static final String DEFAULT_SALT_LENGTH = "5";

// 二维码尺寸
private static final int QRCODE_SIZE = 300;

Expand Down Expand Up @@ -192,20 +197,10 @@ public static String getHash(String hexInput) {
*/
public static String getRandomSalt() {

String length = PropertyUtils.getProperty("salt.length");
String length = PropertyUtils.getProperty("salt.length", DEFAULT_SALT_LENGTH);
int saltLength = Integer.valueOf(length);
String base = "abcdefghijklmnopqrstuvwxyz0123456789";
int randomNum;
char randomChar;
Random random = new Random();
StringBuffer str = new StringBuffer();

for (int i = 0; i < saltLength; i++) {
randomNum = random.nextInt(base.length());
randomChar = base.charAt(randomNum);
str.append(randomChar);
}
return str.toString();
String salt = RandomStringUtils.random(saltLength, true, true);
return salt;
}

/**
Expand Down Expand Up @@ -255,7 +250,7 @@ public static <T> T deserialize(String json, Class<T> clazz) {

/**
* deserialize a JSON String to List.
*
*
* @param json json string
* @param clazz Class.class
* @param <T> the type of the element
Expand Down

0 comments on commit 2fc756f

Please sign in to comment.