/// <summary> /// Logs a user out of their account and sets loginStatus to false /// </summary> /// <param name="accountId">AccountID of the account to be logged out</param> /// <returns>-1 for the gui to sets it's current account ID to</returns> public int Logout(int accountId) { var accs = Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt"); foreach (var account in accs) { if (account._accountId == accountId) { account._loginStatus = false; var temp = new AccountList(accs); temp.SaveCustomerData(); return(-1); } } return(-1); }
private void CustomerSetup() { Random rand = new Random(); var acc0 = new CustomerAccount(0, 0, 0, "GUEST", "djkffsdf", "GUEST ACCOUNT", true); var acc1 = new CustomerAccount(rand.Next(1000000, 9999999), 0, 1, "Bob", "password", "Bob Hitler", false); var acc2 = new CustomerAccount(rand.Next(1000000, 9999999), 0, 2, "Rudy", "password", "Rudy Smeg", false); var acc3 = new CustomerAccount(rand.Next(1000000, 9999999), 0, 3, "Judy", "password", "Judy Spagghettio", false); var acc4 = new CustomerAccount(rand.Next(1000000, 9999999), 0, 4, "John", "password", "John Smith", false); var acc5 = new CustomerAccount(rand.Next(1000000, 9999999), 0, 5, "Clarence", "password", "Clarence Angel", false); AccountList accList = new AccountList(false); accList.AddCustomerAccount(acc0); accList.AddCustomerAccount(acc1); accList.AddCustomerAccount(acc2); accList.AddCustomerAccount(acc3); accList.AddCustomerAccount(acc4); accList.AddCustomerAccount(acc5); accList.SaveCustomerData(); }
/// <summary> /// This function takes the username and password entered by the user. /// It then calls the function to read the Accounts file; this then verifies the entered details /// against the stored details. If both match, it returns the accountId. /// </summary> /// <param name="username">A string containing the username the user entered when attempting to log in.</param> /// <param name="password">A string containing the password the user entered when attempting to log in.</param> /// <returns>If successful, the accountId, else -1 to signal a failure.</returns> public int VerifyLogin(string username, string password) { if (username.StartsWith("admin")) { var accs = Persister.ReadFromBinaryFile <List <AdminAccount> >(@"AdminAccounts.txt"); foreach (var account in accs) { if (account._username == username && account._password == password) { if (account._loginStatus) { return(-2); } account._loginStatus = true; var temp = new AccountList(accs); temp.SaveAdminData(); return(account._accountId); } } return(-1); } else { var accs = Persister.ReadFromBinaryFile <List <CustomerAccount> >(@"Accounts.txt"); foreach (var account in accs) { if (account._username == username && account._password == password) { if (account._loginStatus) { return(-2); } account._loginStatus = true; var temp = new AccountList(accs); temp.SaveCustomerData(); return(account._accountId); } } return(-1); } }