Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package config;
- /**
- * The session identifier generator use to create unused Redis key, this is used by cookie system
- * @author Deisss (LGPLv3)
- * @version 0.1
- */
- public class SessionIdentifierGenerator{
- /**
- * This function generate a unique -not used- key for Redis database storage.
- * The function is mostly used during cookie creation. Use generate instead if you just
- * need a unique string
- * @return The key ready to be sended to Redis database
- */
- public static String create(){
- Redis rd = Redis.getInstance();
- String key = SessionIdentifierGenerator.generate(32);
- while(rd.getJedis().get(key) != null){
- key = SessionIdentifierGenerator.generate(32);
- }
- return key;
- }
- /**
- * This generate a random string of the given size
- * @param length The output length to retrieve
- * @return The generated string
- */
- public static String generate(int length){
- String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
- int charLength = chars.length();
- String pass = "";
- for(int x=0; x<length; x++){
- int i = (int) Math.floor(Math.random() * charLength);
- pass += chars.charAt(i);
- }
- return pass;
- }
- }
Add Comment
Please, Sign In to add comment