Advertisement
Guest User

Restrição de Login

a guest
May 29th, 2015
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 1.40 KB | None | 0 0
  1. Credits by Bian from L2jBrasil
  2.  
  3. ### Eclipse Workspace Patch 1.0
  4. #P L2jFrozen_GameServer
  5. Index: head-src/com/l2jfrozen/loginserver/LoginController.java
  6. ===================================================================
  7. --- head-src/com/l2jfrozen/loginserver/LoginController.java (revision 1118)
  8. +++ head-src/com/l2jfrozen/loginserver/LoginController.java (working copy)
  9. @@ -32,6 +32,9 @@
  10.  import java.sql.ResultSet;
  11.  import java.util.Collection;
  12.  import java.util.Map;
  13. +import java.util.regex.Matcher;
  14. +import java.util.regex.Pattern;
  15. +import java.util.regex.PatternSyntaxException;
  16.  
  17.  import javax.crypto.Cipher;
  18.  
  19. @@ -650,6 +653,9 @@
  20.         // LOGGER it anyway
  21.         Log.add("'" + (user == null ? "null" : user) + "' " + (address == null ? "null" : address.getHostAddress()), "logins_ip");
  22.        
  23. +       if (!isValidLogin(user))
  24. +           return false;
  25. +      
  26.         // player disconnected meanwhile
  27.         if (address == null)
  28.             return false;
  29. @@ -972,4 +978,25 @@
  30.             }
  31.         }
  32.     }
  33. +  
  34. +   public static boolean isValidLogin(String text)
  35. +   {
  36. +       return isValidPattern(text, "^[A-Za-z0-9]{1,16}$");
  37. +   }
  38. +  
  39. +   public static boolean isValidPattern(String text, String regex)
  40. +   {
  41. +       Pattern pattern;
  42. +      
  43. +       try
  44. +       {
  45. +           pattern = Pattern.compile(regex);
  46. +       }
  47. +       catch (PatternSyntaxException e)
  48. +       {
  49. +           pattern = Pattern.compile(".*");
  50. +       }
  51. +       Matcher regexp = pattern.matcher(text);
  52. +       return regexp.matches();
  53. +   }
  54.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement