用户编码生成缩短为12字符

This commit is contained in:
lxp
2026-10-19 13:53:53 +08:00
parent 97f816fffc
commit 8a3ecabdc0
6 changed files with 171 additions and 18 deletions
@@ -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();
}
}