Only allow Alphanumerical characters and underscores when registering a new username
Use RegexUtils in GuiUploadFile
This commit is contained in:
@@ -10,6 +10,7 @@ import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
import eu.crushedpixel.replaymod.utils.EmailAddressUtils;
|
||||
import eu.crushedpixel.replaymod.utils.RegexUtils;
|
||||
import org.lwjgl.util.ReadableColor;
|
||||
|
||||
public class GuiRegister extends AbstractGuiScreen<GuiRegister> {
|
||||
@@ -101,6 +102,8 @@ public class GuiRegister extends AbstractGuiScreen<GuiRegister> {
|
||||
String status = null;
|
||||
if (usernameInput.getText().length() < 5) {
|
||||
status = "replaymod.gui.register.error.shortusername";
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_UNDERSCORE, usernameInput.getText().trim())) {
|
||||
status = "replaymod.gui.register.error.invalidname";
|
||||
} else if (passwordInput.getText().length() < 5) {
|
||||
status = "replaymod.gui.register.error.shortpw";
|
||||
} else if (!EmailAddressUtils.isValidEmailAddress(mailInput.getText())) {
|
||||
|
||||
@@ -11,10 +11,7 @@ import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
||||
import eu.crushedpixel.replaymod.registry.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.utils.ImageUtils;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import eu.crushedpixel.replaymod.utils.*;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
@@ -43,15 +40,11 @@ import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GuiUploadFile extends GuiScreen implements ProgressUpdateListener {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static final Pattern titlePattern = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern tagsPattern = Pattern.compile("[^a-z0-9,]", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private final ResourceLocation textureResource;
|
||||
private DynamicTexture dynTex = null;
|
||||
|
||||
@@ -419,10 +412,11 @@ public class GuiUploadFile extends GuiScreen implements ProgressUpdateListener {
|
||||
boolean enabled = true;
|
||||
if(name.getText().trim().length() < 5 || name.getText().trim().length() > 30) {
|
||||
enabled = false;
|
||||
} else if(titlePattern.matcher(name.getText()).find()) {
|
||||
name.setTextColor(Color.RED.getRGB());
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_SPACE_HYPHEN_UNDERSCORE, name.getText())) {
|
||||
enabled = false;
|
||||
name.setTextColor(Color.RED.getRGB());
|
||||
} else if(tagsPattern.matcher(tags.getText()).find()) {
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_COMMA, tags.getText())) {
|
||||
enabled = false;
|
||||
tags.setTextColor(Color.RED.getRGB());
|
||||
} else {
|
||||
|
||||
@@ -129,6 +129,7 @@ replaymod.gui.register.confirmpw=Confirm Password
|
||||
|
||||
replaymod.gui.register.error.nomatch=Passwords don't match
|
||||
replaymod.gui.register.error.shortusername=Username has to be at least 5 characters long
|
||||
replaymod.gui.register.error.invalidname=Username may only contain letters and numbers
|
||||
replaymod.gui.register.error.shortpw=Password has to be at least 5 characters long
|
||||
replaymod.gui.register.error.authfailed=Could not authenticate your Minecraft account
|
||||
|
||||
|
||||
Reference in New Issue
Block a user