Codergies.VerifyNation 1.0.1

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Codergies.VerifyNation" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Codergies.VerifyNation" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Codergies.VerifyNation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Codergies.VerifyNation --version 1.0.1
                    
#r "nuget: Codergies.VerifyNation, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Codergies.VerifyNation@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Codergies.VerifyNation&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Codergies.VerifyNation&version=1.0.1
                    
Install as a Cake Tool

VerifyNation

Republic of Turkey Identity Number (TCKN) is a lightweight and extensible .NET library developed to perform authentication.

NuGet NuGet Downloads

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:

  1. Length Check: TCKN must have 11 digits and all characters must be digits.
  2. First Digit Check: The first digit of the TCKN cannot be 0.
  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.3 177 5/27/2025
1.0.2 164 5/27/2025
1.0.1 127 4/12/2025
1.0.0 109 4/12/2025

- 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