ActiveLogin.Identity provides parsing and validation of Swedish identities such as Personal Identity Number (svenskt personnummer). Built on NET Standard and packaged as NuGet-packages they are easy to install and use on multiple platforms.
| Project | Description | NuGet |
|---|---|---|
| ActiveLogin.Identity.Swedish | .NET classes handling Personal Identity Number | |
| ActiveLogin.Identity.Swedish.AspNetCore | Validation attributes for ASP.NET Core. |
ActiveLogin.Identity is distributed as packages on NuGet, install using the tool of your choice.
For example using .NET CLI:
dotnet add package ActiveLogin.Identity.Swedishor
dotnet add package ActiveLogin.Identity.Swedish.AspNetCoreSwedishPersonalIdentityNumber provides parsing methods such as SwedishPersonalIdentityNumber.Parse() and SwedishPersonalIdentityNumber.TryParse() that can be used like this:
var rawPersonalIdentityNumber = "990807-2391";
if (SwedishPersonalIdentityNumber.TryParse(rawPersonalIdentityNumber, out var personalIdentityNumber))
{
Console.WriteLine("SwedishPersonalIdentityNumber");
Console.WriteLine(" .ToString(): {0}", personalIdentityNumber.ToString());
Console.WriteLine(" .ToShortString(): {0}", personalIdentityNumber.ToShortString());
Console.WriteLine(" .ToLongString(): {0}", personalIdentityNumber.ToLongString());
Console.WriteLine(" .GetDateOfBirthHint(): {0}", personalIdentityNumber.GetDateOfBirthHint().ToShortDateString());
Console.WriteLine(" .GetAgeHint(): {0}", personalIdentityNumber.GetAgeHint().ToString());
Console.WriteLine(" .GetGenderHint(): {0}", personalIdentityNumber.GetGenderHint().ToString());
}
else
{
Console.Error.WriteLine("Unable to parse the input as a SwedishPersonalIdentityNumber.");
}The code above would output (as of 2018-07-23):
SwedishPersonalIdentityNumber
.ToString(): 990807-2391
.ToShortString(): 990807-2391
.ToLongString(): 199908072391
.GetDateOfBirthHint(): 1999-08-07
.GetAgeHint(): 18
.GetGenderHint(): Male
Some data, such as DateOfBirth, Age and Gender can't be garanteed to reflect the truth due to limitied amount of personal identity numbers per day.
Therefore they are exposed as extension methods and are suffixed with Hint to reflect this.
If used to validate input in an ASP.NET Core MVC project, the SwedishPersonalIdentityNumberAttribute can be used like this:
public class SampleDataModel
{
[SwedishPersonalIdentityNumber]
public string SwedishPersonalIdentityNumber { get; set; }
}For more usecases, samples and inspiration; feel free to browse our unit tests and samples:
The implementation is based on the definitions as described here:
The Swedish word "personnummer" is translted into "personal identity number" by Skatteverket and that's the translation we decided on using as it's used in official documents.
Unforentunately the term "social security number" or SSN is often used even for a swedish personal identity number, even though that is misleading as a SSN is something used in the United States and should not be mixed up with a PIN.
To comply with GDPR and not no expose any real PINs, we are using the official test data for Swedish Personal Identity Numbers provided by Skatteverket.
Some forms of a Swedish Personal Identity Number depends of the age of the person it represents. The "-" will be replaced with a "+" once the person is 100 years old or older. Therefore an overload exists to define at what point in the the data should be represented. Useful for parsing old data or printing data fore the future.
Integrating your systems with market leading authentication services.
ActiveLogin is an Open Source project built on .NET Standard that makes it easy to integrate with leading Swedish authentication services like BankID.
It also provide examples of how to use it with the popular OpenID Connect & OAuth 2.0 Framework IdentityServer and provides a template for hosting the solution in Microsoft Azure. In addition, ActiveLogin also contain convenient modules that help you work with and handle validation of Swedish Personal Identity Number (svenskt personnummer).
We are very open to community contributions to ActiveLogin. You'll need a basic understanding of Git and GitHub to get started. The easiest way to contribute is to open an issue and start a discussion. If you make code changes, submit a pull request with the changes and a description. Don’t forget to always provide tests that cover the code changes.
ActiveLogin is licensed under the very permissive MIT license for you to be able to use it in commercial or non-commercial applications without many restrictions.
ActiveLogin is built on or uses the following great open source products: