summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--TwoStepsAuthenticator.TestApp/ViewModel.cs7
-rw-r--r--TwoStepsAuthenticator/Authenticator.cs8
2 files changed, 8 insertions, 7 deletions
diff --git a/TwoStepsAuthenticator.TestApp/ViewModel.cs b/TwoStepsAuthenticator.TestApp/ViewModel.cs
index 191569f..8bfeb9b 100644
--- a/TwoStepsAuthenticator.TestApp/ViewModel.cs
+++ b/TwoStepsAuthenticator.TestApp/ViewModel.cs
@@ -72,10 +72,9 @@ namespace TwoStepsAuthenticatorTestApp
public ViewModel()
{
- var auth = new TwoStepsAuthenticator.Authenticator();
- this.Key = auth.GenerateKey();
+ var authenticator = new TwoStepsAuthenticator.Authenticator();
+ this.Key = authenticator.GenerateKey();
timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, timerCallback, App.Current.Dispatcher);
- //timer.Elapsed += timer_Elapsed;
timer.Start();
}
@@ -98,6 +97,8 @@ namespace TwoStepsAuthenticatorTestApp
{
var auth = new TwoStepsAuthenticator.Authenticator();
Code = auth.GetCode(this.Key);
+
+ auth.CheckCode(key, Code);
}
}
}
diff --git a/TwoStepsAuthenticator/Authenticator.cs b/TwoStepsAuthenticator/Authenticator.cs
index a026e57..0f0e298 100644
--- a/TwoStepsAuthenticator/Authenticator.cs
+++ b/TwoStepsAuthenticator/Authenticator.cs
@@ -9,11 +9,11 @@ namespace TwoStepsAuthenticator
{
public class Authenticator
{
- private static UsedCodesManager usedCodes = new UsedCodesManager();
+ private static Lazy<UsedCodesManager> usedCodes = new Lazy<UsedCodesManager>();
public string GenerateKey()
{
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
var random = new Random();
var keyChars = new char[16];
for (int i = 0; i < 16; i++)
@@ -68,7 +68,7 @@ namespace TwoStepsAuthenticator
public bool CheckCode(string secret, string code)
{
- if (usedCodes.IsCodeUsed(secret, code))
+ if (usedCodes.Value.IsCodeUsed(secret, code))
return false;
var baseTime = DateTime.Now;
@@ -77,7 +77,7 @@ namespace TwoStepsAuthenticator
var checkTime = baseTime.AddSeconds(30 * i);
if (GetCode(secret, checkTime) == code)
{
- usedCodes.AddCode(secret, code);
+ usedCodes.Value.AddCode(secret, code);
return true;
}
}