GoogleAuthenticator 3.0.0

.NET Standard 2.0 .NET Framework 4.6.2
dotnet add package GoogleAuthenticator --version 3.0.0
NuGet\Install-Package GoogleAuthenticator -Version 3.0.0
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="GoogleAuthenticator" Version="3.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GoogleAuthenticator --version 3.0.0
#r "nuget: GoogleAuthenticator, 3.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install GoogleAuthenticator as a Cake Addin
#addin nuget:?package=GoogleAuthenticator&version=3.0.0

// Install GoogleAuthenticator as a Cake Tool
#tool nuget:?package=GoogleAuthenticator&version=3.0.0

GoogleAuthenticator

Simple, easy to use server-side two-factor authentication library for .NET that works with Google Authenticator

Build Status NuGet Status

Install-Package GoogleAuthenticator

Usage

Additional examples at Google.Authenticator.WinTest and Google.Authenticator.WebSample

using Google.Authenticator;

string key = Guid.NewGuid().ToString().Replace("-", "").Substring(0, 10);

TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
SetupCode setupInfo = tfa.GenerateSetupCode("Test Two Factor", "user@example.com", key, false, 3);

string qrCodeImageUrl = setupInfo.QrCodeSetupImageUrl;
string manualEntrySetupCode = setupInfo.ManualEntryKey;

imgQrCode.ImageUrl = qrCodeImageUrl;
lblManualSetupCode.Text = manualEntrySetupCode;

// verify
TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
bool result = tfa.ValidateTwoFactorPIN(key, txtCode.Text)

Update history

3.0.0

  • Removed support for legacy .Net Framework. Lowest supported versions are now netstandard2.0 and .Net 4.6.2.
  • All use of System.Drawing has been removed. In 2.5, only Net 6.0 avoided System.Drawing.
  • Linux installations no longer need to ensure libgdiplus is installed as it is no longer used.
  • Changed from using EscapeUriString to EscapeDataString to encode the "account title" as the former is obsolete in .Net 6. This changes the value in the generated data string from a@b.com to a%40b.com. We have tested this with Google Authenticator, Lastpass Authenticator and Microsoft Authenticator. All three of them handle it correctly and all three recognise that it is still the same account so this should be safe in most cases.

2.5.0

Now runs on .Net 6.0.
Technically the QR Coder library we rely on still does not fully support .Net 6.0 so it is possible there will be other niggling issues, but for now all tests pass for .Net 6.0 on both Windows and Linux.

Common Pitfalls

  • Old documentation indicated specifying width and height for the QR code, but changes in QR generation now uses pixels per module (QR "pixel") so using a value too high will result in a huge image that can overrun memory allocations
  • Don't use the secret key and ManualEntryKey interchangeably. ManualEntryKey is used to enter into the authenticator app when scanning a QR code is impossible and is derived from the secret key (discussion example)
  • With versions prior to 3.0 only, on linux, you need to ensure libgdiplus is installed if you want to generate QR Codes. See https://github.com/codebude/QRCoder/issues/227.
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.2

  • .NETStandard 2.0

NuGet packages (22)

Showing the top 5 NuGet packages that depend on GoogleAuthenticator:

Package Downloads
FourRoads.TelligentCommunity101.GoogleMfa

Integration with Google MFA

FleekDeveloper.GoogleAuthenticator

Custom extension for Google Authenticator

Qore360.Framework.Interfaces

Package Description

FourRoads.TelligentCommunity100.GoogleMfa

Integration with Google MFA

UniCryptoLab.Web.Framework

UniCryptoLab.Web.Framework

GitHub repositories (5)

Showing the top 5 popular GitHub repositories that depend on GoogleAuthenticator:

Repository Stars
nopSolutions/nopCommerce
ASP.NET Core eCommerce software. nopCommerce is a free and open-source shopping cart.
ONLYOFFICE/CommunityServer
Free open source office suite with business productivity tools: document and project management, CRM, mail aggregator.
grandnode/grandnode
Open source, headless, multi-tenant eCommerce platform built with .NET Core, MongoDB, AWS DocumentDB, Azure CosmosDB, Vue.js.
grandnode/grandnode2
Free, Open source, Fast, Headless, Multi-tenant eCommerce platform built with .NET Core, MongoDB, AWS DocumentDB, Azure CosmosDB, LiteDB, Vue.js.
ONLYOFFICE/DocSpace
Platform for creating your own online office.
Version Downloads Last updated
3.0.0 106,326 6/1/2022
3.0.0-beta2 283 5/26/2022
3.0.0-beta1 434 5/6/2022
2.5.0 55,165 4/13/2022
2.4.0 97,952 12/28/2021
2.3.0 54,865 11/30/2021
2.2.0 211,696 7/13/2021
2.1.1 318,121 12/3/2020
2.0.1 301,264 1/10/2020
2.0.0 5,416 1/2/2020
1.2.1 992,221 12/7/2016
1.2.0 74,611 9/23/2015
1.1.0 5,741 1/7/2015
1.0.0 1,778 9/8/2014