Skip to content

Commit

Permalink
chore: refactor register window (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
WeylonSantana authored Aug 1, 2024
1 parent c82cd07 commit 143d1b3
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 289 deletions.
12 changes: 12 additions & 0 deletions Intersect (Core)/Security/PasswordUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Security.Cryptography;
using System.Text;

namespace Intersect.Security;

public partial class PasswordUtils
{
public static string ComputePasswordHash(string password)
{
return BitConverter.ToString(SHA256.HashData(Encoding.UTF8.GetBytes(password ?? string.Empty))).Replace("-", string.Empty);
}
}
10 changes: 3 additions & 7 deletions Intersect.Client/Interface/Menu/LoginWindow.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.Security.Cryptography;
using System.Text;
using Intersect.Client.Core;
using Intersect.Client.Framework.File_Management;
using Intersect.Client.Framework.Gwen.Control;
Expand All @@ -9,6 +7,7 @@
using Intersect.Client.Interface.Game.Chat;
using Intersect.Client.Localization;
using Intersect.Client.Networking;
using Intersect.Security;
using Intersect.Utilities;

namespace Intersect.Client.Interface.Menu;
Expand Down Expand Up @@ -177,7 +176,7 @@ private void TryLogin()
var password = _savedPass;
if (!_useSavedPass)
{
password = ComputePasswordHash(_txtPassword.Text.Trim());
password = PasswordUtils.ComputePasswordHash(_txtPassword.Text.Trim());
}

Globals.WaitingOnServer = true;
Expand Down Expand Up @@ -209,17 +208,14 @@ private void LoadCredentials()
_chkSavePass.IsChecked = true;
}

private static string ComputePasswordHash(string password) =>
BitConverter.ToString(SHA256.HashData(Encoding.UTF8.GetBytes(password ?? string.Empty))).Replace("-", string.Empty);

private void SaveCredentials()
{
string username = string.Empty, password = string.Empty;

if (_chkSavePass.IsChecked)
{
username = _txtUsername.Text.Trim();
password = _useSavedPass ? _savedPass : ComputePasswordHash(_txtPassword.Text.Trim());
password = _useSavedPass ? _savedPass : PasswordUtils.ComputePasswordHash(_txtPassword.Text.Trim());
}

Globals.Database.SavePreference("Username", username);
Expand Down
6 changes: 3 additions & 3 deletions Intersect.Client/Interface/Menu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void HandleReceivedConfiguration()

private readonly SettingsWindow mSettingsWindow;

private readonly RegisterWindow mRegisterWindow;
private readonly RegistrationWindow mRegisterWindow;

private readonly ResetPasswordWindow mResetPasswordWindow;

Expand Down Expand Up @@ -73,7 +73,7 @@ public MainMenu(Canvas menuCanvas) : base(menuCanvas)
mLoginWindow = new LoginWindow(menuCanvas, this);

//Register Controls
mRegisterWindow = new RegisterWindow(menuCanvas, this);
mRegisterWindow = new RegistrationWindow(menuCanvas, this);

//Forgot Password Controls
mForgotPasswordWindow = new ForgotPasswordWindow(menuCanvas, this);
Expand Down Expand Up @@ -228,7 +228,7 @@ internal void SwitchToWindow<TMainMenuWindow>() where TMainMenuWindow : IMainMen
{
mLoginWindow.Show();
}
else if (typeof(TMainMenuWindow) == typeof(RegisterWindow))
else if (typeof(TMainMenuWindow) == typeof(RegistrationWindow))
{
mRegisterWindow.Show();
}
Expand Down
4 changes: 2 additions & 2 deletions Intersect.Client/Interface/Menu/MainMenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private void ButtonRegisterOnClicked(Base sender, ClickedEventArgs arguments)
{
if (Networking.Network.InterruptDisconnectsIfConnected())
{
_mainMenu.SwitchToWindow<RegisterWindow>();
_mainMenu.SwitchToWindow<RegistrationWindow>();
}
else
{
Expand Down Expand Up @@ -163,7 +163,7 @@ private void RemoveRegisterEvents()
private void RegisterConnected(object? sender, EventArgs eventArgs)
{
RemoveRegisterEvents();
_mainMenu.SwitchToWindow<RegisterWindow>();
_mainMenu.SwitchToWindow<RegistrationWindow>();
}

#endregion Register
Expand Down
277 changes: 0 additions & 277 deletions Intersect.Client/Interface/Menu/RegisterWindow.cs

This file was deleted.

Loading

0 comments on commit 143d1b3

Please sign in to comment.