Skip to content

Commit

Permalink
Updated username regex to not allow uppercase characters
Browse files Browse the repository at this point in the history
  • Loading branch information
JuniorDark committed Jun 9, 2023
1 parent d319a7d commit 086b25b
Show file tree
Hide file tree
Showing 6 changed files with 4,781 additions and 4,703 deletions.
4 changes: 2 additions & 2 deletions RHLauncher.RegForm/RegForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 16 additions & 5 deletions RHLauncher.RegForm/RegForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public partial class RegForm : Form
private readonly System.Windows.Forms.Timer resendTimer = new();
private int secondsLeft = 60;

[GeneratedRegex("^(?=.*[a-zA-Z])[a-zA-Z0-9]+$")]
private static partial Regex MyRegex();

public RegForm()
{
InitializeComponent();
Expand Down Expand Up @@ -271,7 +268,9 @@ private void ReturnLabel_Click(object sender, EventArgs e)
private bool NameTextBoxValid = false;
private void NameTextBox_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(NameTextBox.Text) || NameTextBox.Text.Length < 6 || NameTextBox.Text.Length > 16 || !MyRegex().IsMatch(NameTextBox.Text))
Regex nameregex = new("^(?=.*[a-z])[a-z0-9]+$");

if (string.IsNullOrEmpty(NameTextBox.Text) || NameTextBox.Text.Length < 6 || NameTextBox.Text.Length > 16 || !nameregex.IsMatch(NameTextBox.Text) || HasUppercase(NameTextBox.Text))
{
if (string.IsNullOrEmpty(NameTextBox.Text))
{
Expand All @@ -287,7 +286,14 @@ private void NameTextBox_TextChanged(object sender, EventArgs e)
NamePictureBox.Image = imageListTips.Images[0];
NameTextBoxValid = false;
}
else if (!MyRegex().IsMatch(NameTextBox.Text))
else if (HasUppercase(NameTextBox.Text))
{
NameDescLabel.Text = LocalizedStrings.UsernameDescLabelUppercase;
NameDescLabel.ForeColor = Color.Red;
NamePictureBox.Image = imageListTips.Images[0];
NameTextBoxValid = false;
}
else if (!nameregex.IsMatch(NameTextBox.Text))
{
NameDescLabel.Text = LocalizedStrings.UsernameDescLabelInvalid;
NameDescLabel.ForeColor = Color.Red;
Expand All @@ -304,6 +310,11 @@ private void NameTextBox_TextChanged(object sender, EventArgs e)
CheckFormS2Validity();
}

private static bool HasUppercase(string text)
{
return text.Any(char.IsUpper);
}

private bool PasswordTextBoxValid = false;
private void PasswordTextBox_TextChanged(object sender, EventArgs e)
{
Expand Down
Loading

0 comments on commit 086b25b

Please sign in to comment.