Skip to content

Commit

Permalink
Add support for different phone number countries
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessecar96 committed Jul 7, 2023
1 parent 82adc8d commit 6a3108c
Show file tree
Hide file tree
Showing 6 changed files with 2,134 additions and 16 deletions.
23 changes: 10 additions & 13 deletions Steam Desktop Authenticator/LoginForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,18 @@ private async void btnSteamLogin_Click(object sender, EventArgs e)
switch (linkResponse)
{
case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
string phoneNumber = "";
while (!PhoneNumberOkay(phoneNumber))

// Show the phone input form
PhoneInputForm phoneInputForm = new PhoneInputForm(account);
phoneInputForm.ShowDialog();
if (phoneInputForm.Canceled)
{
InputForm phoneNumberForm = new InputForm("Enter your phone number in the following format: +{cC} phoneNumber. EG, +1 123-456-7890");
phoneNumberForm.txtBox.Text = "+1 ";
phoneNumberForm.ShowDialog();
if (phoneNumberForm.Canceled)
{
this.Close();
return;
}

phoneNumber = FilterPhoneNumber(phoneNumberForm.txtBox.Text);
this.Close();
return;
}
linker.PhoneNumber = phoneNumber;

linker.PhoneNumber = phoneInputForm.PhoneNumber;
linker.PhoneCountryCode = phoneInputForm.CountryCode;
break;

case AuthenticatorLinker.LinkResult.AuthenticatorPresent:
Expand Down
161 changes: 161 additions & 0 deletions Steam Desktop Authenticator/PhoneInputForm.Designer.cs

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

75 changes: 75 additions & 0 deletions Steam Desktop Authenticator/PhoneInputForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using SteamAuth;
using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace Steam_Desktop_Authenticator
{
public partial class PhoneInputForm : Form
{
private SteamGuardAccount Account;
public string PhoneNumber;
public string CountryCode;
public bool Canceled;

public PhoneInputForm(SteamGuardAccount account)
{
this.Account = account;
InitializeComponent();
}

private void btnSubmit_Click(object sender, EventArgs e)
{
this.PhoneNumber = txtPhoneNumber.Text;
this.CountryCode = txtCountryCode.Text;

if (this.PhoneNumber[0] != '+')
{
MessageBox.Show("Phone number must start with + and country code.", "Phone Number", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}

this.Close();
}

private void txtPhoneNumber_KeyPress(object sender, KeyPressEventArgs e)
{
// Allow pasting
if (Char.IsControl(e.KeyChar))
return;

// Only allow numbers, spaces, and +
var regex = new Regex(@"[^0-9\s\+]");
if (regex.IsMatch(e.KeyChar.ToString()))
{
e.Handled = true;
}
}

private void txtCountryCode_KeyPress(object sender, KeyPressEventArgs e)
{
// Allow pasting
if (Char.IsControl(e.KeyChar))
return;

// Only allow letters
var regex = new Regex(@"[^a-zA-Z]");
if (regex.IsMatch(e.KeyChar.ToString()))
{
e.Handled = true;
}
}

private void txtCountryCode_Leave(object sender, EventArgs e)
{
// Always uppercase
txtCountryCode.Text = txtCountryCode.Text.ToUpper();
}

private void btnCancel_Click(object sender, EventArgs e)
{
this.Canceled = true;
this.Close();
}
}
}
Loading

0 comments on commit 6a3108c

Please sign in to comment.