Reverse/boylizards.protect_me/source/Validator/Program.cs

52 lines
1.6 KiB
C#
Raw Normal View History

2024-10-12 12:26:06 +08:00
namespace Validator
{
internal class Program
{
static void Main()
{
Console.Write("Please enter a Name: ");
string? name = Console.ReadLine();
if (string.IsNullOrEmpty(name))
Console.WriteLine("Name cannot be empty.");
else
{
Console.Write("Please enter a Serial: ");
string? serial = Console.ReadLine();
string ErrReason = "";
if (ValidateNameSerial(name, serial ?? "", ref ErrReason))
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Passed");
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Failed: " + ErrReason);
}
}
Console.ResetColor();
Console.ReadLine();
return;
}
static bool ValidateNameSerial(string name, string serial, ref string ErrReason)
{
int length = name.Length;
if (length <= 7)
{
ErrReason = "Name length must be greater than 7";
return false;
}
else
{
string temp2 = length + name.Remove(3, 5);
if ((length / (double)temp2.Length) + temp2 == serial)
return true;
ErrReason = "Wrong Serial";
return false;
}
}
}
}