Skip to content

Commit ab8ba05

Browse files
committed
* Added remarks/clarfications that 160+ bits are a 'good practice' despite the 80 bit default
1 parent 40ca92f commit ab8ba05

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ When a user wants to setup two-factor auth (or, more correctly, multi-factor aut
3030

3131
```c#
3232
var tfa = new TwoFactorAuth("MyCompany");
33-
var secret = tfa.CreateSecret();
33+
// Though the default is an 80 bits secret (for backwards compatibility reasons) we
34+
// recommend creating 160+ bits secrets (see RFC 4226 - Algorithm Requirements)
35+
var secret = tfa.CreateSecret(160);
3436
```
3537

36-
The `CreateSecret()` method accepts two arguments: `bits` (default: `80`) and `cryptoSecureRequirement` (default: `RequireSecure`). The former is the number of bits generated for the shared secret. Make sure this argument is a multiple of 8 and, again, keep in mind that not all combinations may be supported by all apps. Google Authenticator seems happy with 80 and 160, the default is set to 80 because that's what most sites (that I know of) currently use. The latter is used to ensure that the secret is cryptographically secure; if you don't care very much for cryptographically secure secrets you can specify `AllowInsecure` and use a non-cryptographically secure RNG provider.
38+
The `CreateSecret()` method accepts two arguments: `bits` (default: `80`) and `cryptoSecureRequirement` (default: `RequireSecure`). The former is the number of bits generated for the shared secret. Make sure this argument is a multiple of 8 and, again, keep in mind that not all combinations may be supported by all apps. Google Authenticator seems happy with 80 and 160, the default is set to 80 because that's what most sites (that I know of) currently use; however a value of 160 or higher is recommended (see [RFC 4226 - Algorithm Requirements](https://tools.ietf.org/html/rfc4226#section-4)). The latter is used to ensure that the secret is cryptographically secure; if you don't care very much for cryptographically secure secrets you can specify `AllowInsecure` and use a non-cryptographically secure RNG provider.
3739

3840
```c#
3941
// Display shared secret

TwoFactorAuth.Net.Demo/Controllers/HomeController.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Web;
5-
using System.Web.Mvc;
6-
using TwoFactorAuthNet;
1+
using System.Web.Mvc;
72
using TwoFactorAuthNet.Demo.Models;
83

94
namespace TwoFactorAuthNet.Demo.Controllers
@@ -20,7 +15,9 @@ public ActionResult Index()
2015
public ActionResult Step1()
2116
{
2217
if (string.IsNullOrEmpty((string)Session["secret"]))
23-
Session.Add("secret", tfa.CreateSecret());
18+
// Though the default is an 80 bits secret (for backwards compatibility reasons) we
19+
// recommend creating 160+ bits secrets (see RFC 4226 - Algorithm Requirements)
20+
Session.Add("secret", tfa.CreateSecret(160));
2421

2522
return View(tfa);
2623
}

TwoFactorAuth.Net.Demo/Views/Home/Step1.cshtml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
<pre>
1212
var tfa = new TwoFactorAuth("MyCompany");
13-
var secret = tfa.CreateSecret();</pre>
13+
// Though the default is an 80 bits secret (for backwards compatibility reasons) we
14+
// recommend creating 160+ bits secrets (see RFC 4226 - Algorithm Requirements)
15+
var secret = tfa.CreateSecret(160);</pre>
1416

15-
<p>The <code>CreateSecret()</code> method accepts two arguments: <code>bits</code> (default: <code>80</code>) and <code>cryptoSecureRequirement</code> (default: <code>RequireSecure</code>). The former is the number of bits generated for the shared secret. Make sure this argument is a multiple of 8 and, again, keep in mind that not all combinations may be supported by all apps. Google authenticator seems happy with 80 and 160, the default is set to 80 because that's what most sites (that I know of) currently use. The latter is used to ensure that the secret is cryptographically secure; if you don't care very much for cryptographically secure secrets you can specify <code>AllowInsecure</code> and use a non-cryptographically secure RNG provider.</p>
17+
<p>The <code>CreateSecret()</code> method accepts two arguments: <code>bits</code> (default: <code>80</code>) and <code>cryptoSecureRequirement</code> (default: <code>RequireSecure</code>). The former is the number of bits generated for the shared secret. Make sure this argument is a multiple of 8 and, again, keep in mind that not all combinations may be supported by all apps. Google authenticator seems happy with 80 and 160, the default is set to 80 because that's what most sites (that I know of) currently use; however a value of 160 or higher is recommended (see <a href="https://tools.ietf.org/html/rfc4226#section-4">RFC 4226 - Algorithm Requirements</a>). The latter is used to ensure that the secret is cryptographically secure; if you don't care very much for cryptographically secure secrets you can specify <code>AllowInsecure</code> and use a non-cryptographically secure RNG provider.</p>
1618

1719
<pre>
1820
// Display shared secret
@@ -39,13 +41,15 @@
3941
<pre>
4042
// Display QR code to user
4143
&lt;p&gt;Scan the following image with your app:&lt;/p&gt;
42-
&lt;p&gt;&lt;img src="@@tfa.GetQrCodeImageAsDataUri("Bob Ross", secret)"&gt;&lt;/p&gt;</pre>
44+
&lt;p&gt;&lt;img src="@@tfa.GetQrCodeImageAsDataUri("Bob Ross", secret)"&gt;&lt;/p&gt;
45+
&lt;p&gt;Or enter the following secret in your app: @@Session["secret"]&gt;&lt;/p&gt;</pre>
4346

4447
<p>This results in:</p>
4548

4649
<div class="well">
4750
<p>Scan the following image with your app:</p>
4851
<p><img src="@Model.GetQrCodeImageAsDataUri("Bob Ross", (string)Session["secret"])"></p>
52+
<p>Or enter the following secret in your app: @Session["secret"]</p>
4953
</div>
5054

5155
<p>Did you scan (or manually enter) the secret?</p>

0 commit comments

Comments
 (0)