Codergies.VerifyNation
1.0.1
See the version list below for details.
dotnet add package Codergies.VerifyNation --version 1.0.1
NuGet\Install-Package Codergies.VerifyNation -Version 1.0.1
<PackageReference Include="Codergies.VerifyNation" Version="1.0.1" />
<PackageVersion Include="Codergies.VerifyNation" Version="1.0.1" />
<PackageReference Include="Codergies.VerifyNation" />
paket add Codergies.VerifyNation --version 1.0.1
#r "nuget: Codergies.VerifyNation, 1.0.1"
#:package Codergies.VerifyNation@1.0.1
#addin nuget:?package=Codergies.VerifyNation&version=1.0.1
#tool nuget:?package=Codergies.VerifyNation&version=1.0.1
VerifyNation
Republic of Turkey Identity Number (TCKN) is a lightweight and extensible .NET library developed to perform authentication.
Features
- TCKN standard algorithmic validation
- TCKN length and first digit check
- Extensible validation rules
- .NET 9.0+ support
- Easy integration with Dependency Injection
- Full unit test coverage
Installation
Using Package Manager Console:
Install-Package VerifyNation
Using the .NET CLI:
dotnet add package VerifyNation
Usage
Basic Usage
using VerifyNation;
// Validation process
string tckn = "10000000146";
var validator = new VerifyNation.Core.TcknValidator();
var result = validator.Validate(tckn);
if (result.IsValid)
{
Console.WriteLine("TCKN is valid.");
}
else
{
Console.WriteLine("TCKN is invalid: " + string.Join(", ", result.ErrorMessages));
}
Use with Dependency Injection
// Startup.cs or Program.cs
using VerifyNation.Extensions;
// Extension on IServiceCollection
services.AddTcknValidator();
// In Controller or Service class
public class MyService
{
private readonly IValidator<string> _tcknValidator;
public MyService(IValidator<string> tcknValidator)
{
_tcknValidator = tcknValidator;
}
public void ValidateTckn(string tckn)
{
var result = _tcknValidator.Validate(tckn);
// ...processes
}
}
Error Handling
using VerifyNation.Exceptions;
try
{
var validator = new VerifyNation.Core.TcknValidator();
var result = validator.ValidateWithException("invalid-tckn");
// Works on successful verification
}
catch (ValidationException ex)
{
// Works in case of error
Console.WriteLine($"Validation error: {ex.Message}");
Console.WriteLine($"Errors: {string.Join(", ", ex.Errors)}");
}
Validation Rules
TcknValidator includes the following validation rules:
- Length Check: TCKN must have 11 digits and all characters must be digits.
- First Digit Check: The first digit of the TCKN cannot be 0.
- Algorithmic Verification:
- The algorithmically calculated result of the first 10 digits must yield the 11th digit.
- The algorithmically calculated result of the first 9 digits must give the 10th digit.
Add Custom Validation Rules
using VerifyNation.Abstract;
using VerifyNation.Core;
// Defining a custom rule
public class CustomTcknRule : IValidationRule<string>
{
public bool Validate(IValidationContext context, string input)
{
// Custom validation logic
return true; // or false
}
}
// Using the special rule
var validator = new TcknValidator.Core.TcknValidator();
validator.AddRule(new CustomTcknRule());
var result = validator.Validate("10000000146");
License
This project is licensed under the MIT license. For more information, see LICENSE.
Contribution
To contribute, please open an issue or submit a pull request.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
- TCKN standard algorithmic validation
- TCKN length and first digit check
- Extensible validation rules
- .NET 9.0+ support
- Easy integration with Dependency Injection
- Full unit test coverage