Skip to content
This repository has been archived by the owner on Jan 6, 2024. It is now read-only.

Commit

Permalink
First Run Security Question Setup
Browse files Browse the repository at this point in the history
  • Loading branch information
VoxDroid committed Dec 20, 2023
1 parent 6233b5c commit 41885d7
Show file tree
Hide file tree
Showing 5 changed files with 1,201 additions and 8 deletions.
88 changes: 80 additions & 8 deletions Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ private void loginbutton_Click(object sender, EventArgs e)
lblError.Text = string.Empty;
string username1 = username.Text;
string password1 = password.Text;

if (IsDatabaseConnected())
{
if (string.IsNullOrWhiteSpace(username1) || string.IsNullOrWhiteSpace(password1))
Expand All @@ -644,11 +645,33 @@ private void loginbutton_Click(object sender, EventArgs e)
lblError.Enabled = false;
lblError.Visible = false;
lblError.Text = string.Empty;
Main mainForm = new Main();
mainForm.Show();
mainForm.LoggedInUser = currentlyLoggedInUser;

this.Hide();
bool securityQuestionsExist = CheckSecurityQuestionsExist();

if (securityQuestionsExist)
{
Main mainForm = new Main();
mainForm.Show();
mainForm.LoggedInUser = currentlyLoggedInUser;

this.Hide();
}
else
{
DialogResult result = MessageBox.Show("It seems like it's your first time logging in. Security questions are required before continuing. Would you like to set them up now?", "Security Questions Setup Required", MessageBoxButtons.YesNo);

if (result == DialogResult.Yes)
{
SetupSQ setupForm = new SetupSQ();
setupForm.ShowDialog();
}
else
{
lblError.Enabled = true;
lblError.Visible = true;
lblError.Text = "First Set Up is Required.";
}
}
}
else
{
Expand All @@ -667,6 +690,32 @@ private void loginbutton_Click(object sender, EventArgs e)
}
}

private bool CheckSecurityQuestionsExist()
{
string sqlSelect = "SELECT * FROM securityquestions WHERE sqs_id = 1";

try
{
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();

using (MySqlCommand selectCommand = new MySqlCommand(sqlSelect, connection))
{
using (MySqlDataReader reader = selectCommand.ExecuteReader())
{
return reader.Read();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show($"Error: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}

private string AuthenticateUser(string username, string password)
{
try
Expand Down Expand Up @@ -736,6 +785,7 @@ private void LoginEnter()
lblError.Text = string.Empty;
string username1 = username.Text;
string password1 = password.Text;

if (IsDatabaseConnected())
{
if (string.IsNullOrWhiteSpace(username1) || string.IsNullOrWhiteSpace(password1))
Expand All @@ -755,11 +805,33 @@ private void LoginEnter()
lblError.Enabled = false;
lblError.Visible = false;
lblError.Text = string.Empty;
Main mainForm = new Main();
mainForm.Show();
mainForm.LoggedInUser = currentlyLoggedInUser;

this.Hide();
bool securityQuestionsExist = CheckSecurityQuestionsExist();

if (securityQuestionsExist)
{
Main mainForm = new Main();
mainForm.Show();
mainForm.LoggedInUser = currentlyLoggedInUser;

this.Hide();
}
else
{
DialogResult result = MessageBox.Show("It seems like it's your first time logging in. Security questions are required before continuing. Would you like to set them up now?", "Security Questions Setup Required", MessageBoxButtons.YesNo);

if (result == DialogResult.Yes)
{
SetupSQ setupForm = new SetupSQ();
setupForm.ShowDialog();
}
else
{
lblError.Enabled = true;
lblError.Visible = true;
lblError.Text = "First Set Up is Required.";
}
}
}
else
{
Expand Down
9 changes: 9 additions & 0 deletions SPAAT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,12 @@
<Compile Include="Recovery.Designer.cs">
<DependentUpon>Recovery.cs</DependentUpon>
</Compile>
<Compile Include="SetupSQ.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SetupSQ.Designer.cs">
<DependentUpon>SetupSQ.cs</DependentUpon>
</Compile>
<Compile Include="SubPages\ModBudMan.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down Expand Up @@ -648,6 +654,9 @@
<EmbeddedResource Include="Recovery.resx">
<DependentUpon>Recovery.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="SetupSQ.resx">
<DependentUpon>SetupSQ.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="SubPages\ModBudMan.resx">
<DependentUpon>ModBudMan.cs</DependentUpon>
</EmbeddedResource>
Expand Down
Loading

0 comments on commit 41885d7

Please sign in to comment.