Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Specifying Maximum Login Attempts

PriapusPriapus Posts: 36Member
Hi,
I've got a login form that authenticates a user against a database. I'm trying to implement a function whereby if a user enters 3 invalid passwords in succession, a message is displayed and the application shuts down. I'm using a for loop 2 achieve this(shown in bold text), but i can't get it to work. Any suggestions for how i should implement this bit of functionality? Below is the login function for the form.
[code syntax = c#]
public partial class LoginForm : Form
{
private LoginObject aLoginObject;
public LoginForm()
{
InitializeComponent();
aLoginObject = new LoginObject();
}

private void LoginForm_Load(object sender, EventArgs e)
{
this.BackColor = Color.Azure;
}

private void btnEnter_Click(object sender, EventArgs e)
{
try
{
string resultMsg = "";
byte passConfirm = 0;
int loginAttempts = 0;

// validate user input
// if no input from the user, display error message
if (txtPassword.Text.Trim().Equals(""))
{
MessageBox.Show("You must enter a password!");
txtPassword.Focus();
txtPassword.Text = "";
}
else
{
passConfirm = aLoginObject.login(txtPassword.Text, ref resultMsg);
if(passConfirm == 1)
{
// Success
// MessageBox.Show(resultMsg);
// Enter the application.Show the main menu tree view
TreeViewMenuForm aTreeViewMenuForm;
aTreeViewMenuForm = new TreeViewMenuForm();
aTreeViewMenuForm.Show();
}
else if (passConfirm == 2)
{
// Invalid password
MessageBox.Show(resultMsg);
txtPassword.Focus();
txtPassword.Text = "";
}
else
{
// 255 DAtabase error
MessageBox.Show(resultMsg);
}
// if user enters incorrect password 3 times
// the application will shutdown
[b]for (int i = 0; i < 3; i++)
{
loginAttempts = loginAttempts + 1;
if (loginAttempts > 3)
{
MessageBox.Show("You do not have access to this wallet");
Application.Exit();
}[/b]
}

}
}// end try

catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}// end of btnEnter_click() method

private void btnClear_Click(object sender, EventArgs e)
{
txtPassword.Text = "";
txtPassword.Focus();
}

private void mnuExit_Click(object sender, EventArgs e)
{
Application.Exit();
}

}
[/code]

Comments

Sign In or Register to comment.