Commit ec2728d7 by stylefeng

修改生成随机字符串的方法

parent 61310256
......@@ -17,6 +17,7 @@ package com.stylefeng.guns.core.shiro;
import com.stylefeng.guns.common.constant.Const;
import com.stylefeng.guns.common.constant.factory.ConstantFactory;
import com.stylefeng.guns.core.util.ToolUtil;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.crypto.hash.SimpleHash;
......@@ -25,7 +26,6 @@ import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.ByteSource;
import java.util.List;
import java.util.Random;
/**
* shiro工具类
......@@ -64,14 +64,7 @@ public class ShiroKit {
* @return
*/
public static String getRandomSalt(int length) {
String base = "abcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();
return ToolUtil.getRandomString(length);
}
/**
......
......@@ -28,6 +28,23 @@ import java.util.Map.Entry;
* 高频方法集合类
*/
public class ToolUtil {
/**
* 获取随机位数的字符串
*
* @author fengshuonan
* @Date 2017/8/24 14:09
*/
public static String getRandomString(int length) {
String base = "abcdefghijklmnopqrstuvwxyz0123456789";
Random random = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; i++) {
int number = random.nextInt(base.length());
sb.append(base.charAt(number));
}
return sb.toString();
}
/**
* 判断一个对象是否是时间类型
......@@ -65,40 +82,6 @@ public class ToolUtil {
}
/**
* @Description 主键id
* @author fengshuonan
*/
public static String getUid() {
return getRandomNum();
}
/**
* @Description 随机数字
* @author fengshuonan
*/
public static String getRandomNum() {
return Calendar.getInstance().getTimeInMillis() + generateCellPhoneValNum();
}
/**
* @Description 获取电话号码
* @author fengshuonan
*/
public static String generateCellPhoneValNum() {
String[] beforeShuffle = new String[]{"1", "2", "3", "4", "5", "6",
"7", "8", "9", "0"};
List<String> list = Arrays.asList(beforeShuffle);
Collections.shuffle(list);
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
buffer.append(list.get(i));
}
String afterShuffle = buffer.toString();
String result = afterShuffle.substring(3, 9);
return result;
}
/**
* 比较两个对象是否相等。<br>
* 相同的条件有两个,满足其一即可:<br>
* 1. obj1 == null && obj2 == null; 2. obj1.equals(obj2)
......
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