Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
*.userosscache
*.sln.docstates

# directories
.idea

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

Expand Down
16 changes: 16 additions & 0 deletions BankingSoftware/BankingSoftware.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>BankingSoftware</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Folder Include="Storage\Accounts"/>
<Folder Include="Storage\Users"/>
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions BankingSoftware/Common/AddSymbol.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace BankingSoftware.Common;

public static class AddSymbol
{
public static void AddBreakLine(int symbolLength = 80, string symbol = "-")
{
for (var i = 0; i < symbolLength; i++)
Console.Write(symbol);

Console.WriteLine("");
}

public static void AddBreakLines(int symbolLength = 80, int lineLength = 3, string symbol = "-")
{
for (var k = 0; k < lineLength; k++)
AddBreakLine(symbolLength, symbol);

Console.WriteLine("\n");
}
}
29 changes: 29 additions & 0 deletions BankingSoftware/Common/Hash.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Security.Cryptography;
using System.Text;

namespace BankingSoftware.Common;

// to hash input values
public class Hash
{
private const int keySize = 16;
private const int iterations = 350000;
private readonly HashAlgorithmName hashAlgorithm = HashAlgorithmName.SHA256;

public string HashValues(string[] values)
{
var joinedValues = string.Join("", values);

var salt = new UTF8Encoding(true).GetBytes(joinedValues);

var hash = Rfc2898DeriveBytes.Pbkdf2(
Encoding.UTF8.GetBytes(joinedValues),
salt,
iterations,
hashAlgorithm,
keySize);

return Convert.ToHexString(hash);
}
}
130 changes: 130 additions & 0 deletions BankingSoftware/Common/VerifyInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace BankingSoftware.Common;

// verify input by user
public static partial class VerifyInput
{
public static string VerifyForStringOnly(string input)
{
while (
string.IsNullOrEmpty(input)
|| string.IsNullOrWhiteSpace(input)
|| input.Any(char.IsNumber)
|| input.Any(c =>
{
char.IsNumber(c);
char.IsSymbol(c);
char.IsPunctuation(c);
char.IsSeparator(c);

return false;
})
)
{
Console.WriteLine("Input must not contain any number or symbol");
Console.Write("Please input new value: ");
input = Console.ReadLine();
}

Console.WriteLine("Input is valid");
return input;
}

public static string VerifyForStringAndNumber(string stringNumber)
{
while (
string.IsNullOrEmpty(stringNumber)
|| string.IsNullOrWhiteSpace(stringNumber)
|| stringNumber.Any(c =>
{
char.IsLetter(c);
char.IsPunctuation(c);
char.IsSymbol(c);

return false;
})
)
{
Console.WriteLine("Input must not contain any number or symbol");
Console.Write("Please input new value: ");
stringNumber = Console.ReadLine();
}

Console.WriteLine("Input is valid");
return stringNumber;
}

public static int VerifyNumber(int number)
{
while (
string.IsNullOrEmpty(number.ToString())
|| string.IsNullOrWhiteSpace(number.ToString())
|| number.ToString().Any(c =>
{
char.IsSymbol(c);
char.IsPunctuation(c);
char.IsLetter(c);


return false;
})
)
{
Console.WriteLine("Input must not contain any letter or symbol");
Console.Write("Please input your value: ");
number = int.Parse(Console.ReadLine());
}

Console.WriteLine("Number is valid");
return number;
}

public static string VerifyPassword(string password)
{
while (
string.IsNullOrEmpty(password)
|| string.IsNullOrWhiteSpace(password)
)
{
Console.WriteLine("Input must not contain any space");
Console.Write("Please input new value: ");
password = Console.ReadLine();
}

Console.WriteLine("Password is valid");
return password;
}

[GeneratedRegex("^\\(?([0-9]{3})\\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$")]
private static partial Regex MyRegex();

public static string VerifyPhoneNumber(string phoneNumber)
{
while (!MyRegex().IsMatch(phoneNumber))
{
Console.WriteLine("Input must not contain any letter or symbol");
Console.Write("Please input new value: ");
phoneNumber = Console.ReadLine();
}

Console.WriteLine("Phone number is valid");
return phoneNumber;
}

public static string VerifyEmail(string email)
{
var regex = @"^[^@\s]+@[^@\s]+\.(com|net|org|gov)$";

while (!Regex.IsMatch(email, regex, RegexOptions.IgnoreCase))
{
Console.Write("Input a valid email: ");
email = Console.ReadLine();
}

Console.WriteLine("Email is valid.");
return email;
}
}
24 changes: 24 additions & 0 deletions BankingSoftware/Common/WriteFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.IO;
using System.Text;

namespace BankingSoftware.Common;

// for writing to text files
public static class WriteFile
{
public static void WriteLine(string lineText, string fileName)
{
using var fs = File.AppendText(fileName);
fs.Write(lineText);
}

public static void WriteLines(string[] linesTexts, string fileName)
{
using var fs = File.OpenWrite(fileName);
for (var i = 0; i < linesTexts.Length; i++)
{
var info = new UTF8Encoding(true).GetBytes(linesTexts[i] + "\n");
fs.Write(info, 0, info.Length);
}
}
}
120 changes: 120 additions & 0 deletions BankingSoftware/Modules/AccountModule.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.IO;
using BankingSoftware.Common;

namespace BankingSoftware.Modules;

// Module to handle account operations
public class AccountModule
{
private static string GetAccountFile(in string userLogin, string accountStoragePath)
{
var charFileName = userLogin.Split();
var accountFileName = new Hash().HashValues(charFileName);
var accountFilenameWithPath = accountStoragePath + accountFileName + ".txt";

return accountFilenameWithPath;
}

private static string[] GetAccountSummary(string accountFilename)
{
var accountInfo = File.ReadAllLines(accountFilename);

return accountInfo;
}

public static void Deposit(in string userLogin, string accountStoragePath)
{
var accountFilename = GetAccountFile(userLogin, accountStoragePath);

var accountInfo = GetAccountSummary(accountFilename);
foreach (var info in accountInfo) Console.WriteLine(info);

Console.Write("Please enter the amount you want to deposit: ");
var depositAmount = int.Parse(Console.ReadLine());

while (depositAmount is string && depositAmount < 0) depositAmount = int.Parse(Console.ReadLine());

var depositAmountLine = accountInfo[2].Split(": $");
var depositTimeLine = accountInfo[3].Split(": ");
depositAmountLine[1] = depositAmount.ToString();
depositTimeLine[1] = DateTime.Now.ToString();

accountInfo[2] = string.Join(": $", depositAmountLine);
accountInfo[3] = string.Join(": ", depositTimeLine);

var totalLine = accountInfo[4].Split(": $");

var totalAmount = int.Parse(totalLine[1]) + depositAmount;
totalLine[1] = totalAmount.ToString();
accountInfo[4] = string.Join(": $", totalLine);

Console.WriteLine("You've deposited ${0} to your account", depositAmount);

Console.WriteLine("\nYour total amount is ${0}", totalAmount);

WriteFile.WriteLines(accountInfo, accountFilename);
}

public static void Withdraw(in string userLogin, string accountStoragePath)
{
var accountFilename = GetAccountFile(userLogin, accountStoragePath);

var accountInfo = GetAccountSummary(accountFilename);
var totalLine = accountInfo[4].Split(": $");

Console.Write("Please enter the amount you want to withdraw: ");
var withdrawAmount = int.Parse(Console.ReadLine());
var currentTotal = int.Parse(totalLine[1]);
var finalTotalAmount = currentTotal - withdrawAmount;

while (withdrawAmount is string && withdrawAmount < 0)
{
Console.WriteLine("Your withdraw amount should be greater than Zero");
withdrawAmount = int.Parse(Console.ReadLine());
finalTotalAmount = currentTotal - withdrawAmount;
}

if (finalTotalAmount < 0)
{
Console.WriteLine("Insufficient balance.");
}
else
{
var withdrawAmountLine = accountInfo[0].Split(": $");
var withdrawTimeLine = accountInfo[1].Split(": ");
withdrawAmountLine[1] = withdrawAmount.ToString();
withdrawTimeLine[1] = DateTime.Now.ToString();

accountInfo[0] = string.Join(": ", withdrawAmountLine);
accountInfo[1] = string.Join(": ", withdrawTimeLine);

totalLine[1] = finalTotalAmount.ToString();
accountInfo[4] = string.Join(": $", totalLine);

Console.WriteLine("You've withdrawn ${0} from your account", withdrawAmount);

Console.WriteLine("\nYour have ${0} left in your account", finalTotalAmount);

WriteFile.WriteLines(accountInfo, accountFilename);
}
}

public static void ViewAccountBalance(in string userLogin, string accountStoragePath)
{
var accountFilename = GetAccountFile(userLogin, accountStoragePath);

var accountBalance = GetAccountSummary(accountFilename)[4];

Console.WriteLine("Your account balance is {0}", accountBalance);
}

public static void ViewAccountSummary(in string userLogin, string accountStoragePath)
{
var accountFilename = GetAccountFile(userLogin, accountStoragePath);

var accountInfo = GetAccountSummary(accountFilename);

foreach (var info in accountInfo) Console.WriteLine(info);
}
}
Loading