登录token优化
This commit is contained in:
48
src/main/java/com/mini/mybigscreen/utils/KeyUtil.java
Normal file
48
src/main/java/com/mini/mybigscreen/utils/KeyUtil.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.mini.mybigscreen.utils;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class KeyUtil {
|
||||
|
||||
public static String ObjKey(int length, int type) {
|
||||
Random random = new Random();
|
||||
StringBuffer key = new StringBuffer();
|
||||
if (type == 1) {
|
||||
String str = "0123456789";
|
||||
for (int i = 0; i < length; ++i) {
|
||||
//从62个的数字或字母中选择
|
||||
int number = random.nextInt(10);
|
||||
//将产生的数字通过length次承载到key中
|
||||
key.append(str.charAt(number));
|
||||
}
|
||||
return key.toString();
|
||||
} else if (type == 2) {
|
||||
String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
||||
for (int i = 0; i < length; ++i) {
|
||||
//从62个的数字或字母中选择
|
||||
int number = random.nextInt(36);
|
||||
//将产生的数字通过length次承载到key中
|
||||
key.append(str.charAt(number));
|
||||
}
|
||||
return key.toString();
|
||||
} else if (type == 3) {
|
||||
String str = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
for (int i = 0; i < length; ++i) {
|
||||
//从62个的数字或字母中选择
|
||||
int number = random.nextInt(36);
|
||||
//将产生的数字通过length次承载到key中
|
||||
key.append(str.charAt(number));
|
||||
}
|
||||
return key.toString();
|
||||
} else {
|
||||
String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
for (int i = 0; i < length; ++i) {
|
||||
//从62个的数字或字母中选择
|
||||
int number = random.nextInt(62);
|
||||
//将产生的数字通过length次承载到key中
|
||||
key.append(str.charAt(number));
|
||||
}
|
||||
return key.toString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user