I have coded what you see so far. basically need to make it that the user gets 3 tries. AFter the first fail, gives an error like " error: 2 more tries left", same again with the 2nd fail. Onm the third it brings a message up saying " Error: too many tries " then does this.Close() to close the program. I cannot seem to figure out where to put a maxattempts type thing because i tried it in the foreach and it makes the attempts 8. The rest of the code reads in from a text file, uses a class to split '|', and then stores in said variables.
public partial class Pin : Form
{
private static List<Accounts> currentAccounts;
public string pathToFile = "H:\\c#assessmentO\\accounts.txt";
public Pin()
{
InitializeComponent();
currentAccounts = File.ReadAllLines(pathToFile)
.Skip(1)
.Select(v => Accounts.FromPipe(v))
.ToList();
}
private void button1_Click(object sender, EventArgs e)
{
string userAccNo = txtAccNo.Text;
string userPinNo = txtPinNo.Text;
string userForename = "";
string userSurname = "";
string userAddress = "";
string userBalance = "";
string userPurchasedToday = "";
bool match = false;
int lineNumber = 0;
int numberOfLines = 0;
if ((userAccNo == "999999") && (userPinNo == "4321"))
{
MessageBox.Show("SHUTDOWN ACTIVATED");
this.Close();
}
else
{
foreach (Accounts Account in currentAccounts)
{
numberOfLines++;
if ((Account.AccNu.ToString() == userAccNo) && (Account.PinNu.ToString() == userPinNo))
{
match = true;
lineNumber = numberOfLines + 1;
userForename = Account.Forename.ToString();
userSurname = Account.Surname.ToString();
userAddress = Account.Address.ToString();
userBalance = Account.Balance.ToString();
userPurchasedToday = Account.PurchasesToday.ToString();
}
}
}
if (match == true)
{
MessageBox.Show("Access Granted: You can now access the System");
Options frmOptions = new Options(userAccNo, userPinNo, pathToFile, lineNumber, userForename, userSurname, userAddress, userBalance, userPurchasedToday);
this.Hide();
frmOptions.ShowDialog();
}
}
}
Suppose to give only 3 tries for the password.