{"id":26452921,"url":"https://github.com/ssg/turkishid","last_synced_at":"2025-05-16T16:09:18.625Z","repository":{"id":23326606,"uuid":"26686769","full_name":"ssg/TurkishId","owner":"ssg","description":"Validator/generator for Turkish Republic Citizen ID numbers (TC Kimlik No)","archived":false,"fork":false,"pushed_at":"2025-05-09T18:20:57.000Z","size":143,"stargazers_count":83,"open_issues_count":0,"forks_count":33,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-05-16T16:08:30.116Z","etag":null,"topics":["c-sharp","libraries","nuget","turkey"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ssg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["ssg"]}},"created_at":"2014-11-15T17:01:06.000Z","updated_at":"2025-05-12T11:53:12.000Z","dependencies_parsed_at":"2025-05-09T05:24:12.819Z","dependency_job_id":"4aee84f2-1727-4a3a-b054-956880a02139","html_url":"https://github.com/ssg/TurkishId","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2FTurkishId","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2FTurkishId/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2FTurkishId/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ssg%2FTurkishId/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ssg","download_url":"https://codeload.github.com/ssg/TurkishId/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254564197,"owners_count":22092123,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","libraries","nuget","turkey"],"created_at":"2025-03-18T18:28:52.075Z","updated_at":"2025-05-16T16:09:18.607Z","avatar_url":"https://github.com/ssg.png","language":"C#","funding_links":["https://github.com/sponsors/ssg"],"categories":[],"sub_categories":[],"readme":"[![NuGet Version](https://img.shields.io/nuget/v/TurkishId.svg)](https://www.nuget.org/packages/TurkishId/)\n![Build status](https://github.com/ssg/TurkishId/actions/workflows/build.yml/badge.svg)\n\nTurkishId\n=========\nValidator, model binder and generator tool for Turkish Republic's citizen ID numbers. I've decided to give this a shot last \nnight while I was waiting for a download. And Turkish ID numbers were really popular in Turkish social\nmedia last week. The Id number is called \"T.C. Kimlik No\" (Turkish Republic Identity Number). I decided to \nuse English translation to allow easier handling in international projects.\n\nUsage\n-----\nI wanted the `TurkishIdNumber` representation to be used anywhere in the code as a value to pass around when \nusing id's allowing to assume an instance is already validated saving you from redundant checks.\n\nWhen you want to use it as a representation of an ID number:\n\n```csharp\nusing TurkishId;\nvar id = new TurkishIdNumber(\"12345678901\");\n// throws ArgumentException when invalid parameter is passed\n```\n\nor if you just want to validate it:\n\n```csharp\nusing TurkishId;\nbool reallyValid = TurkishIdNumber.IsValid(\"12345678901\");\n```\n\nYou can also use the classic `TryParse`:\n\n```csharp\nusing TurkishId;\nif (TurkishIdNumber.TryParse(value, out var id))\n{\n    // ...\n}\n```\n\nor with a nullable return value which can be used with pattern matching:\n\n```csharp\nusing TurkishId;\nif (TurkishIdNumber.TryParse(value) is TurkishIdNumber id))\n{\n    // ...\n}\n```\n\nNuGet package is here: \u003chttps://www.nuget.org/packages/TurkishId/\u003e\n\nTurkishId.ModelBinder\n---------------------\nThere is also a model binder package that you can install at \u003chttps://www.nuget.org/packages/TurkishId.ModelBinder\u003e.\nIt's a plug'n'play model binder which lets you to use TurkishIdNumber class directly in your model declarations.\n\nIt's not part of the original package because you may not want to have whole MVC as a dependency.\n\nTo set it up in an ASP.NET Core project, use this syntax in your `ConfigureServices()` method in your\n`Startup` class:\n\n```csharp\nservices.AddMvc(options =\u003e\n{\n  options.ModelBinderProviders.Insert(0, new TurkishIdModelBinderProvider());\n});\n```\n\nand you're done. If you'd like to use it in your Razor Pages app use `AddMvcOptions` instead:\n\n```csharp\nservices.AddRazorPages()\n  .AddMvcOptions(options =\u003e options.ModelBinderProviders.Insert(0, new TurkishIdModelBinderProvider()));\n```\n\nor, alternatively, if you only use controllers, you can add it to your `AddControllers` options:\n\n```csharp\nservices.AddControllers(options =\u003e\n{\n  options.ModelBinderProviders.Insert(0, new TurkishIdModelBinderProvider());\n});\n```\n\nThe model binder package will use ASP.NET Core's model binding message providers. You can now localize them\nlike how you do any other model binder.\n\nPerformance\n------------\nThis is probably one of the fastest implementations on .NET. I didn't grind so much on performance but\nit can easily handle millions of validations per second on my Core i7. \n\nAlgorithm\n----------\nTurkish Republic's ID structure and verification is simple. It's an eleven digit number. \nIf we name each digit as _d(n)_ where leftmost digit is called _d1_ and the rightmost _d11_, a given ID is valid if:\n\n\u003e _d1_ \u003e 0\n\nand\n\n\u003e _n_ = (_d1_ + _d3_ + _d5_ + _d7_ + _d9_) * 7 - (_d2_ + _d4_ + _d6_ + _d8_)\n\u003e\n\u003e if _n_ \u003c 0 then _n_ = _n_ + 10\n\u003e\n\u003e _d10_ = _n_ mod 10\n\nand\n\n\u003e _d11_ = sum(_d1_.._d10_) mod 10 \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssg%2Fturkishid","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fssg%2Fturkishid","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fssg%2Fturkishid/lists"}