blob: 611a3b15a795ad664139006e8c5d5a5a308f3d5a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package com.juick.util;
import java.util.Random;
/**
* Created by aalexeev on 11/14/16.
*/
public class UserUtils {
private UserUtils() {
throw new IllegalStateException();
}
private static final String ABCDEF = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
public static String generateHash(final int len) {
Random rnd = new Random();
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++) {
sb.append(ABCDEF.charAt(rnd.nextInt(ABCDEF.length())));
}
return sb.toString();
}
public static boolean checkUserNameValid(final String uname) {
return uname != null && uname.length() >= 2 && uname.length() <= 16 && uname.matches("[a-zA-Z0-9\\-]+");
}
}
|