Advertisement
Guest User

Untitled

a guest
Oct 31st, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Personal_Accounts_Information
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14.  
  15. List<Accounts> users = new List<Accounts>();
  16. //Decides were the .txt file will be saved to.
  17. string path = @"D:\Personal Accounts Information.txt";
  18.  
  19.  
  20. //This will out put all the information that has allready be created in the .txt file to the console so the user
  21. // can see all the information they have saved.
  22. using (StreamReader sr = new StreamReader(path))
  23. {
  24. string line = sr.ReadToEnd();
  25. Console.WriteLine(line);
  26. }
  27. bool willContinue = true;
  28.  
  29. do
  30. {
  31. string accountName;
  32. string userName;
  33. string passWord;
  34.  
  35. Console.WriteLine("Enter your Account Name or type exit to quit program. ");
  36. accountName = Console.ReadLine();
  37.  
  38. if (accountName != "exit")
  39. {
  40.  
  41. Console.WriteLine("Enter your User Name for the " + accountName);
  42. userName = Console.ReadLine();
  43. Console.WriteLine("Enter your Password for the " + userName, "assotied with" + accountName);
  44. passWord = Console.ReadLine();
  45.  
  46. Accounts account = new Accounts(accountName, userName, passWord);
  47. users.Add(account);
  48. }
  49. else
  50. {
  51. willContinue = false;
  52. }
  53.  
  54. } while (willContinue);
  55.  
  56. using (StreamWriter sw = new StreamWriter(path, true))
  57. {
  58. foreach (Accounts accounts in users)
  59. {
  60. Console.WriteLine(" Account Name: " + accounts.AccountName + " UserName: " + accounts.Username + " Password " + accounts.PassWord);
  61.  
  62. sw.WriteLine("Account Name: " + accounts.AccountName);
  63. sw.WriteLine("UserName: " + accounts.Username + "\r\n");
  64. sw.WriteLine("Password: " + accounts.PassWord + "\r\n");
  65. }
  66. }
  67.  
  68. }
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82. class Accounts
  83. {
  84.  
  85. public string backing;
  86. public Accounts(string accountName, string userName, string passWord)
  87. {
  88. this.AccountName = accountName;
  89. this.Username = userName;
  90. this.PassWord = passWord;
  91. }
  92.  
  93. public string AccountName
  94. {
  95. // gets and sets the string var accountName
  96. get
  97. {
  98. return this.accountName;
  99. }
  100. set
  101. {
  102. if (IsValidateAccountName(value))
  103. {
  104. this.accountName = value;
  105. }
  106. else
  107. {
  108. //Will throw a exception if the user inputs a space in the account name.
  109. throw new Exception("No Space's Allowed In Account Name");
  110. }
  111. }
  112.  
  113. }
  114.  
  115. public string Username
  116. {
  117. get
  118. {
  119. return this.userName;
  120. }
  121. private set
  122. {
  123. if (IsValidateUserName(value))
  124. {
  125. this.userName = value;
  126. }
  127. else
  128. {
  129. throw new Exception("No Space's Allowed In UserName");
  130. }
  131. }
  132. }
  133.  
  134. public string PassWord
  135. {
  136. get
  137. {
  138. return this.password;
  139. }
  140. private set
  141. {
  142. if (IsValidatePassWord(value))
  143. {
  144. this.password = value;
  145. }
  146. else
  147. {
  148. throw new Exception("No Space's Allowed In Password");
  149. }
  150. }
  151. }
  152.  
  153. private bool IsValidatePassWord(string value)
  154. {
  155. //If the password does not contain a space then return true.
  156. bool isValid = (!value.Contains(" "));
  157. return isValid;
  158. }
  159.  
  160. private bool IsValidateUserName(string value)
  161. {
  162. bool isValid = (!value.Contains(" "));
  163. return isValid;
  164. }
  165.  
  166. private bool IsValidateAccountName(string value)
  167. {
  168. bool isValid = (!value.Contains(" "));
  169. return isValid;
  170. }
  171.  
  172.  
  173. // member variables
  174. private string accountName;
  175. private string password;
  176. private string userName;
  177. }
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement