using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Security.Cryptography;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Collections;
using System.Net.Sockets;
public static class TestExtensions
public static string TrimLength(this string str, int length)
return str.Length > length ? str.Substring(0, length) : str;
public static string CreateSalt()
Random random = new Random();
int saltSize = random.Next(minSaltSize, maxSaltSize);
byte[] saltBytes = new byte[saltSize];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetNonZeroBytes(saltBytes);
return Convert.ToBase64String(saltBytes);
public static string CreateHash(string hashString)
SHA256Managed hash = new SHA256Managed();
return Convert.ToBase64String(hash.ComputeHash(hash.ComputeHash(Encoding.UTF8.GetBytes(hashString))));
public static async Task<bool> TestTask1()
Console.WriteLine("Task1");
public static async Task<bool> TestTask2()
Console.WriteLine("Task2");
public static void Test()
string IpAddressString = "204.236.238.95";
IPAddress hostIPAddress = IPAddress.Parse(IpAddressString);
IPHostEntry hostInfo = Dns.GetHostByAddress(hostIPAddress);
IPAddress[] address = hostInfo.AddressList;
String[] alias = hostInfo.Aliases;
Console.WriteLine("Host name : " + hostInfo.HostName);
Console.WriteLine("\nAliases :");
for(int index=0; index < alias.Length; index++) {
Console.WriteLine(alias[index]);
Console.WriteLine("\nIP address list : ");
for(int index=0; index < address.Length; index++) {
Console.WriteLine(address[index]);
catch(System.Net.Sockets.SocketException e)
Console.WriteLine("SocketException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
Console.WriteLine("FormatException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
catch(ArgumentNullException e)
Console.WriteLine("ArgumentNullException caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
Console.WriteLine("Exception caught!!!");
Console.WriteLine("Source : " + e.Source);
Console.WriteLine("Message : " + e.Message);
[JsonPropertyName("name_1")]
public string Name{ get;set;}
public static string byteCode(string password)
using (var cryptoProvider = System.Security.Cryptography.SHA1.Create())
byte[] passwordHash = cryptoProvider.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
string result = "new byte[] { " +
String.Join(",", passwordHash.Select(x => "0x" + x.ToString("x2")).ToArray())
public static byte[] byteCodes(string password)
using (var cryptoProvider = System.Security.Cryptography.SHA1.Create())
return cryptoProvider.ComputeHash(System.Text.Encoding.UTF8.GetBytes(password));
public static void Main()
string stageQAPassword = "PKbJRWHJzN2brqbXY9AQ";
string stageAdminPassword = "PKbJRWHJzN2brqbXY9Aa";
string prodAdminPassword = "KKbJRWHJzN2brqbXY9AQ";
Console.WriteLine(new byte[] { 0x02,0x6d,0xbc,0x71,0x07,0x92,0xfd,0x8c,0x27,0x15,0x8d,0x5f,0x4e,0x33,0x99,0x18,0xc6,0x62,0x0b,0x3c } == byteCodes(stageQAPassword));
Console.WriteLine($"STAGE QA => {byteCode(stageQAPassword)}");
Console.WriteLine($"STAGE Admin => {byteCode(stageAdminPassword)}");
Console.WriteLine($"PROD Admin => {byteCode(prodAdminPassword)}");
Console.WriteLine(DateTime.Parse("08/20/2020").AddDays(30));
var connectionString = @"data source=MY-PC\SQLEXPRESS;";
var pattern = @"(data source=)((\w|\-)+?\\\w+?)\;";
var newConnectionString = Regex.Replace(connectionString, pattern, "$2" + "something");
Console.WriteLine(newConnectionString.TrimLength(1));
var salt = TestExtensions.CreateSalt();
var hash = TestExtensions.CreateHash("password");
Console.WriteLine($"Salt : {salt}");
Console.WriteLine($"Password : {hash}");
var enrollmentDate = GetEnrollmentTriggerDate(triggerDays, planDays);
var renewalDate = enrollmentDate.AddDays(planDays);
Console.WriteLine($"\n\nEnrollmentDate = {enrollmentDate}\nRenewalDate = {renewalDate}\n");
enrollmentDate = GetEnrollmentTriggerDateMonths(triggerDays, planMonths);
renewalDate = enrollmentDate.AddMonths(planMonths);
Console.WriteLine($"\n\nEnrollmentDate = {enrollmentDate}\nRenewalDate = {renewalDate}\n");
Console.WriteLine(DateTimeOffset.UtcNow.AddDays(-3).ToUnixTimeMilliseconds());
var redemptionDateTimeFromEpoch = DateTimeOffset.FromUnixTimeMilliseconds(1598891769999).DateTime.ToUniversalTime();
Console.WriteLine(redemptionDateTimeFromEpoch.Kind);
Console.WriteLine(redemptionDateTimeFromEpoch);
enrollmentDate = GetEnrollmentTriggerDate(triggerDays, planDays);
renewalDate = enrollmentDate.AddDays(planDays);
Console.WriteLine($"\n\nEnrollmentDate = {enrollmentDate}\nRenewalDate = {renewalDate}\n");
public static DateTime GetEnrollmentTriggerDate(int daysBeforeRenewal, int Days)
var enrollmentDate = DateTime.UtcNow.Date;
enrollmentDate = DateTime.UtcNow
.AddDays(daysBeforeRenewal);
public static DateTime GetEnrollmentTriggerDateMonths(int daysBeforeRenewal, int months)
var enrollmentDate = DateTime.UtcNow.Date;
enrollmentDate = DateTime.UtcNow
.AddDays(daysBeforeRenewal);