diff --git a/FraudulentBank.sln b/FraudulentBank.sln new file mode 100644 index 0000000..e2f0edd --- /dev/null +++ b/FraudulentBank.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32929.385 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FraudulentBank", "FraudulentBank\FraudulentBank.csproj", "{917B68DA-F0CB-4F4F-8CEE-6CE34E642A28}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {917B68DA-F0CB-4F4F-8CEE-6CE34E642A28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {917B68DA-F0CB-4F4F-8CEE-6CE34E642A28}.Debug|Any CPU.Build.0 = Debug|Any CPU + {917B68DA-F0CB-4F4F-8CEE-6CE34E642A28}.Release|Any CPU.ActiveCfg = Release|Any CPU + {917B68DA-F0CB-4F4F-8CEE-6CE34E642A28}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AF8FD3AB-96BA-4ACB-8BBD-24990CE4331B} + EndGlobalSection +EndGlobal diff --git a/FraudulentBank/Activity.cs b/FraudulentBank/Activity.cs new file mode 100644 index 0000000..399fd00 --- /dev/null +++ b/FraudulentBank/Activity.cs @@ -0,0 +1,165 @@ +using System; + +public class Activity +{ + public static void Deposit(string fileName, string accountNumber) + { + string[] lines = File.ReadAllLines(fileName); + + var line = lines.FirstOrDefault(l => l.StartsWith(accountNumber + ",")); + + if (line != null) + { + + string[] values = line.Split(','); + decimal balance = decimal.Parse(values[4]); + + Console.WriteLine("Enter amount to deposit:"); + var inputAmt = Console.ReadLine(); + if (string.IsNullOrEmpty(inputAmt)) + { + Console.WriteLine("---INVALID DEPOSIT AMOUNT NOTIFICATION---"); + Console.WriteLine("Invalid Deposit Amount!"); + Console.WriteLine("---------------------"); + } + else if (decimal.TryParse(inputAmt, out decimal amount)) + { + if (amount < 0) + { + Console.WriteLine("---INVALID DEPOSIT AMOUNT NOTIFICATION---"); + Console.WriteLine("Invalid Deposit Amount!"); + Console.WriteLine("---------------------"); + } + else + { + balance += amount; + values[4] = balance.ToString(); + string newLine = string.Join(",", values); + int index = Array.IndexOf(lines, line); + lines[index] = newLine; + File.WriteAllLines(fileName, lines); + + Console.WriteLine("---DEPOSIT NOTIFICATION--"); + Console.WriteLine($"Deposit successful! New balance is: N{balance:N2}"); + Console.WriteLine("-----------------"); + } + } + else + { + Console.WriteLine("---INVALID DEPOSIT AMOUNT NOTIFICATION---"); + Console.WriteLine("Invalid Deposit Amount!"); + Console.WriteLine("---------------------"); + } + } + else + { + Console.WriteLine("Invalid account number. Please try again."); + } + } + + public static void Withdraw(string fileName, string accountNumber) + { + string[] lines = File.ReadAllLines(fileName); + + var line = lines.FirstOrDefault(l => l.StartsWith(accountNumber + ",")); + + if (line != null) + { + string[] values = line.Split(','); + decimal balance = decimal.Parse(values[4]); + + Console.WriteLine("Enter amount to withdraw:"); + var inputAmt = Console.ReadLine(); + if (string.IsNullOrEmpty(inputAmt)) + { + Console.WriteLine("---INVALID WITHDRAWAL AMOUNT NOTIFICATION---"); + Console.WriteLine("Invalid Withdrawal Amount!"); + Console.WriteLine("---------------------"); + } + else if(decimal.TryParse(inputAmt, out decimal amount)) + { + if (amount > balance) + { + Console.WriteLine("---INSUFFICIENT BALANCE"); + Console.WriteLine("Insufficient balance. Please try again."); + Console.WriteLine("--------------------"); + } + else + { + balance -= amount; + values[4] = balance.ToString(); + string newLine = string.Join(",", values); + int index = Array.IndexOf(lines, line); + lines[index] = newLine; + File.WriteAllLines(fileName, lines); + + Console.WriteLine("---WITHDRAWAL NOTIFICATION--"); + Console.WriteLine($"Withdrawal successful! New balance is: N{balance:N2}"); + Console.WriteLine("-------------------"); + } + } + else + { + Console.WriteLine("---INVALID WITHDRAWAL AMOUNT NOTIFICATION---"); + Console.WriteLine("Invalid Withdrawal Amount!"); + Console.WriteLine("---------------------"); + } + + } + else + { + Console.WriteLine("Invalid account number. Please try again."); + } + } + + public static void CheckBalance(string fileName, string accountNumber) + { + string[] lines = File.ReadAllLines(fileName); + + var line = lines.FirstOrDefault(l => l.StartsWith(accountNumber + ",")); + + if (line != null) + { + string[] values = line.Split(','); + decimal balance = decimal.Parse(values[4]); + Console.WriteLine("---BALANCE NOTIFICATION--"); + Console.WriteLine($"Your balance is: N{balance:N2}"); + Console.WriteLine("--------------------"); + } + else + { + Console.WriteLine("Invalid account number. Please try again."); + } + } + public static void ShowAccountSummary(string fileName, string accountNumber) + { + string[] lines = File.ReadAllLines(fileName); + + foreach (string line in lines) + { + string[] fields = line.Split(','); + + if (fields[0] == accountNumber) + { + Console.WriteLine("---ACCOUNT SUMMARY---"); + Console.WriteLine($"Account Number: {fields[0]}"); + Console.WriteLine($"Account Name: {fields[1]}"); + Console.WriteLine($"Email: {fields[2]}"); + double currentBalance = 0; + if (double.TryParse(fields[4], out currentBalance)) + { + Console.WriteLine($"Current Balance: N{currentBalance:N2}"); + } + else + { + Console.WriteLine("Invalid balance format."); + } + Console.WriteLine("--------------------"); + return; + } + } + + Console.WriteLine("Account not found."); + } +} + diff --git a/FraudulentBank/FraudulentBank.csproj b/FraudulentBank/FraudulentBank.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/FraudulentBank/FraudulentBank.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/FraudulentBank/LoggedInMenu.cs b/FraudulentBank/LoggedInMenu.cs new file mode 100644 index 0000000..b7f3c06 --- /dev/null +++ b/FraudulentBank/LoggedInMenu.cs @@ -0,0 +1,42 @@ +using System; + +public class LoggedInMenu +{ + public static void ShowMenu(string fileName, string accountNumber) + { + while (true) + { + Console.WriteLine("Please choose an option:"); + Console.WriteLine("1. Deposit"); + Console.WriteLine("2. Withdraw"); + Console.WriteLine("3. Check balance"); + Console.WriteLine("4. Show Account Summary"); + Console.WriteLine("5. Logout"); + + Console.WriteLine("Choice: "); + var choice = Console.ReadLine(); + + switch (choice) + { + case "1": + Activity.Deposit(fileName, accountNumber); + break; + case "2": + Activity.Withdraw(fileName, accountNumber); + break; + case "3": + Activity.CheckBalance(fileName, accountNumber); + break; + case "4": + Activity.ShowAccountSummary(fileName, accountNumber); + break; + case "5": + Console.WriteLine("Logout successful!"); + return; + default: + Console.WriteLine("Invalid choice. Please try again."); + break; + } + } + } +} diff --git a/FraudulentBank/Program.cs b/FraudulentBank/Program.cs new file mode 100644 index 0000000..1ccccc2 --- /dev/null +++ b/FraudulentBank/Program.cs @@ -0,0 +1,54 @@ +using System; +using System.IO; +using System.Linq; + +namespace FraudulentBank +{ + public class Program + { + static void Main(string[] args) + { + string fileName = Path.Combine(Directory.GetCurrentDirectory(), "accounts.txt"); + + Console.WriteLine("Welcome to the Fraudulent Bank application!"); + + while (true) + { + Console.WriteLine("Please choose an option:"); + Console.WriteLine("1. Signup"); + Console.WriteLine("2. Login"); + Console.WriteLine("3. Exit"); + + Console.WriteLine("Choice: "); + var choice = Console.ReadLine(); + + switch (choice) + { + case "1": + UserAccount.Signup(fileName); + break; + case "2": + string accountNumber = UserAccount.Login(fileName); + + if (accountNumber != null) + { + LoggedInMenu.ShowMenu(fileName, accountNumber); + } + else + { + Console.WriteLine("Invalid credentials. Please try again."); + } + UserAccount.Login(fileName); + break; + case "3": + Console.WriteLine("Have a nice day"); + Environment.Exit(0); + break; + default: + Console.WriteLine("Invalid Option Selection"); + break; + } + } + } + } +} \ No newline at end of file diff --git a/FraudulentBank/UserAccount.cs b/FraudulentBank/UserAccount.cs new file mode 100644 index 0000000..b62c925 --- /dev/null +++ b/FraudulentBank/UserAccount.cs @@ -0,0 +1,91 @@ +using System; +using System.IO; + +public class UserAccount +{ + public static void Signup(string fileName) + { + + Console.WriteLine("Please enter your name:"); + var name = Console.ReadLine(); + + Console.WriteLine("Please enter your email:"); + var email = Console.ReadLine(); + + Console.WriteLine("Please enter your password:"); + var password = Console.ReadLine(); + if (!string.IsNullOrEmpty(name) || !string.IsNullOrEmpty(email) || !string.IsNullOrEmpty(password)) + { + // Generate a unique 10-digit account number starting with 2 + Random rand = new Random(); + string accountNumber = "2" + rand.Next(100000000, 999999999).ToString(); + + using (StreamWriter sw = File.AppendText(fileName)) + { + sw.WriteLine($"{accountNumber},{name},{email},{password},0"); + } + Console.WriteLine("Signup successful!"); + Console.WriteLine("Your account number is " + accountNumber); + LoggedInMenu.ShowMenu(fileName, accountNumber); + } + else + { + Console.WriteLine("Invalid details! You have entered a null or empty value. Try again!!!"); + } + + } + public static string Login(string fileName) + { + + Console.WriteLine("Please enter your account number:"); + var accountNumber = Console.ReadLine(); + + Console.WriteLine("Please enter your password:"); + Console.Write("Enter password: "); + string password = ""; + while (true) + { + ConsoleKeyInfo key = Console.ReadKey(true); + if (key.Key == ConsoleKey.Enter) + { + Console.WriteLine(); + break; + } + else if (key.Key == ConsoleKey.Backspace && password.Length > 0) + { + password = password.Substring(0, password.Length - 1); + Console.Write("\b \b"); + } + else if (!char.IsControl(key.KeyChar)) + { + password += key.KeyChar; + Console.Write("*"); + } + } + + string[] lines = File.ReadAllLines(fileName); + + if (string.IsNullOrWhiteSpace(accountNumber) || string.IsNullOrWhiteSpace(password)) + { + Console.WriteLine("Invalid input. Please try again."); + return null; + } + else + { + foreach (string line in lines) + { + string[] fields = line.Split(','); + if (fields[0] == accountNumber && fields[1] == password) + { + Console.WriteLine("Login successful!"); + //return accountNumber; + } + } + } + return accountNumber; + + //Console.WriteLine("Invalid account number or password. Please try again."); + + } +} +