Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Personal_Accounts_Information
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Accounts> users = new List<Accounts>();
- //Decides were the .txt file will be saved to.
- string path = @"D:\Personal Accounts Information.txt";
- //This will out put all the information that has allready be created in the .txt file to the console so the user
- // can see all the information they have saved.
- using (StreamReader sr = new StreamReader(path))
- {
- string line = sr.ReadToEnd();
- Console.WriteLine(line);
- }
- bool willContinue = true;
- do
- {
- string accountName;
- string userName;
- string passWord;
- Console.WriteLine("Enter your Account Name or type exit to quit program. ");
- accountName = Console.ReadLine();
- if (accountName != "exit")
- {
- Console.WriteLine("Enter your User Name for the " + accountName);
- userName = Console.ReadLine();
- Console.WriteLine("Enter your Password for the " + userName, "assotied with" + accountName);
- passWord = Console.ReadLine();
- Accounts account = new Accounts(accountName, userName, passWord);
- users.Add(account);
- }
- else
- {
- willContinue = false;
- }
- } while (willContinue);
- using (StreamWriter sw = new StreamWriter(path, true))
- {
- foreach (Accounts accounts in users)
- {
- Console.WriteLine(" Account Name: " + accounts.AccountName + " UserName: " + accounts.Username + " Password " + accounts.PassWord);
- sw.WriteLine("Account Name: " + accounts.AccountName);
- sw.WriteLine("UserName: " + accounts.Username + "\r\n");
- sw.WriteLine("Password: " + accounts.PassWord + "\r\n");
- }
- }
- }
- }
- class Accounts
- {
- public string backing;
- public Accounts(string accountName, string userName, string passWord)
- {
- this.AccountName = accountName;
- this.Username = userName;
- this.PassWord = passWord;
- }
- public string AccountName
- {
- // gets and sets the string var accountName
- get
- {
- return this.accountName;
- }
- set
- {
- if (IsValidateAccountName(value))
- {
- this.accountName = value;
- }
- else
- {
- //Will throw a exception if the user inputs a space in the account name.
- throw new Exception("No Space's Allowed In Account Name");
- }
- }
- }
- public string Username
- {
- get
- {
- return this.userName;
- }
- private set
- {
- if (IsValidateUserName(value))
- {
- this.userName = value;
- }
- else
- {
- throw new Exception("No Space's Allowed In UserName");
- }
- }
- }
- public string PassWord
- {
- get
- {
- return this.password;
- }
- private set
- {
- if (IsValidatePassWord(value))
- {
- this.password = value;
- }
- else
- {
- throw new Exception("No Space's Allowed In Password");
- }
- }
- }
- private bool IsValidatePassWord(string value)
- {
- //If the password does not contain a space then return true.
- bool isValid = (!value.Contains(" "));
- return isValid;
- }
- private bool IsValidateUserName(string value)
- {
- bool isValid = (!value.Contains(" "));
- return isValid;
- }
- private bool IsValidateAccountName(string value)
- {
- bool isValid = (!value.Contains(" "));
- return isValid;
- }
- // member variables
- private string accountName;
- private string password;
- private string userName;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement