aboutsummaryrefslogtreecommitdiff
path: root/server-core/src/main/java/com/juick/util
diff options
context:
space:
mode:
Diffstat (limited to 'server-core/src/main/java/com/juick/util')
-rw-r--r--server-core/src/main/java/com/juick/util/UserUtils.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/server-core/src/main/java/com/juick/util/UserUtils.java b/server-core/src/main/java/com/juick/util/UserUtils.java
new file mode 100644
index 00000000..611a3b15
--- /dev/null
+++ b/server-core/src/main/java/com/juick/util/UserUtils.java
@@ -0,0 +1,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\\-]+");
+ }
+}