用户编码生成缩短为12字符
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package com.linkerbot.community.common;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/** 仅用于新用户编码;历史 32 位编码继续有效。 */
|
||||
public final class UserCodes {
|
||||
private static final String ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
|
||||
private static final SecureRandom RANDOM = new SecureRandom();
|
||||
|
||||
private UserCodes() {}
|
||||
|
||||
public static String next() {
|
||||
StringBuilder code = new StringBuilder(12);
|
||||
for (int index = 0; index < 12; index++) {
|
||||
code.append(ALPHABET.charAt(RANDOM.nextInt(ALPHABET.length())));
|
||||
}
|
||||
return code.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user