Send2Email/SendEmail/Form2.cs

63 lines
2.1 KiB
C#
Raw Permalink Normal View History

2024-04-01 13:02:08 -04:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace SendEmail
{
public partial class Form2 : Form
{
/*
* Form2 is only the password prompt to enter the configuration menu
*/
// Global Variables
int wrongCount = 0; // Counts how many times the password is entered incorrectly
const int LIMIT = 5; // The amount of times a password can be tried before exiting
2024-04-01 13:02:08 -04:00
public Form2()
2024-04-01 13:02:08 -04:00
{
InitializeComponent();
}
// Checks the password entered
2024-04-01 13:02:08 -04:00
private void PassButtonClick(object sender, EventArgs e)
{
string input = textBox1.Text;
string encryptedInput = Program.Encrypt(input); // Encrypt the user input
if (encryptedInput == Program.smtp_pass) // If encrypted password is correct
2024-04-01 13:02:08 -04:00
{
this.Hide(); // Hide Form2
var form3 = new Form3(); // Create Form3
form3.Closed += (s, args) => this.Close(); // Attach this.Show() to the Form3.Close() eventhandler, which will show Form2 when Form3 closes.
form3.Show(); // Show Form3
2024-04-01 13:02:08 -04:00
}
else
{
wrongCount++; // Each time this code is reached the wrong counter increases by 1
if (wrongCount == LIMIT) // If we've reached the limit
2024-04-01 13:02:08 -04:00
{
Application.Exit(); // Exit the application
2024-04-01 13:02:08 -04:00
}
else // If we haven't reached the limit
2024-04-01 13:02:08 -04:00
{
// Inform user the number of password attempts remaining.
2024-04-01 13:02:08 -04:00
MessageBox.Show("Incorrect password. " + (LIMIT - wrongCount).ToString() + " attempts remaining.");
}
}
}
// Check if enter key is pressed in the password text box
2024-04-01 13:02:08 -04:00
private void CheckEnter(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
2024-04-01 13:02:08 -04:00
{
PassButtonClick(sender, e);
}
}
}
}