GoogleAuthenticator 3.0.0-beta1

This is a prerelease version of GoogleAuthenticator.
There is a newer version of this package available.
See the version list below for details.
dotnet add package GoogleAuthenticator --version 3.0.0-beta1                
NuGet\Install-Package GoogleAuthenticator -Version 3.0.0-beta1                
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-beta1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GoogleAuthenticator --version 3.0.0-beta1                
#r "nuget: GoogleAuthenticator, 3.0.0-beta1"                
#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.
// Install GoogleAuthenticator as a Cake Addin
#addin nuget:?package=GoogleAuthenticator&version=3.0.0-beta1&prerelease

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

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

1.x Usage

See blog post for usage instructions (1.x only):

https://csharprookie.wordpress.com/2015/03/17/implementing-free-two-factor-authentication-in-net-using-google-authenticator/

2.x 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)

Updates

3.0.0-beta1

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.

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)

Notes

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 Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.2

  • .NETStandard 2.0

NuGet packages (42)

Showing the top 5 NuGet packages that depend on GoogleAuthenticator:

Package Downloads
GeeksCoreLibrary

Geeks Core Library

SenseNet.ContentRepository

Content Repository layer for the sensenet platform.

FourRoads.TelligentCommunity101.GoogleMfa

Integration with Google MFA

QuantFi.Services

Package Description

FleekDeveloper.GoogleAuthenticator

Custom extension for Google Authenticator

GitHub repositories (7)

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
Open-Source eCommerce Platform on .NET Core, MongoDB, AWS DocumentDB, Azure CosmosDB, LiteDB & Vue.js
YAFNET/YAFNET
🌐 YAF.NET - C# ASP.NET Forum
Version Downloads Last updated
3.3.0-beta1 69,176 3/13/2024
3.2.0 669,465 1/12/2024
3.1.1 315,300 10/4/2023
3.1.1-beta1 3,605 5/30/2023
3.1.0 464,262 5/3/2023
3.0.0 1,369,588 6/1/2022
3.0.0-beta2 822 5/26/2022
3.0.0-beta1 1,274 5/6/2022
2.5.0 217,371 4/13/2022
2.4.0 218,454 12/28/2021
2.3.0 128,711 11/30/2021
2.2.0 428,704 7/13/2021
2.1.1 534,454 12/3/2020
2.0.1 464,876 1/10/2020
2.0.0 12,493 1/2/2020
1.2.1 1,383,498 12/7/2016
1.2.0 112,924 9/23/2015
1.1.0 8,927 1/7/2015
1.0.0 3,529 9/8/2014