diff options
author | Alexander Alexeev | 2016-11-14 05:12:02 +0700 |
---|---|---|
committer | Alexander Alexeev | 2016-11-14 05:12:02 +0700 |
commit | ecbc4907669c06c7a71ffda3bd78a163ee1287fe (patch) | |
tree | 2da5b1ff35ed9b63b9c2de01d470e63be5b39ee1 /server-core/src/main/java/com/juick/util | |
parent | aaebdd4913a7e5274018675d12231df8caf227a0 (diff) |
generateHash() and checkuser() moved to Userutils
Diffstat (limited to 'server-core/src/main/java/com/juick/util')
-rw-r--r-- | server-core/src/main/java/com/juick/util/UserUtils.java | 27 |
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\\-]+"); + } +} |