diff options
author | Guillaume Lacasa <guillaumelacasa@hotmail.com> | 2015-11-06 11:23:06 +0100 |
---|---|---|
committer | Guillaume Lacasa <guillaumelacasa@hotmail.com> | 2015-11-06 11:23:06 +0100 |
commit | ecb719c9ca7f802fd14e2a9ee9d2271312129401 (patch) | |
tree | d59f6bd1fcc316a25683839fbc2a38335b9384bf | |
parent | c83f11540872548382946dbbd2ccfd8054e8b62b (diff) | |
parent | 84d0707487263f8e0fec3668c6245af1d0fcb4bd (diff) | |
download | TwoStepsAuthenticator-ecb719c9ca7f802fd14e2a9ee9d2271312129401.zip TwoStepsAuthenticator-ecb719c9ca7f802fd14e2a9ee9d2271312129401.tar.gz TwoStepsAuthenticator-ecb719c9ca7f802fd14e2a9ee9d2271312129401.tar.bz2 |
Merge pull request #6 from 304NotModified/patch-1
Added syntax highlighting to readme
-rw-r--r-- | README.md | 33 |
1 files changed, 21 insertions, 12 deletions
@@ -18,27 +18,30 @@ You can use this library as well for a client application (if you want to create For a client application, you need to save the secret key for your user. <br/> Then, you only have to call the method GetCode(string) : -<pre><code>var secret = user.secretAuthToken; +```c# +var secret = user.secretAuthToken; var authenticator = new TwoStepsAuthenticator.TimeAuthenticator(); var code = authenticator.GetCode(secret); -</code></pre> +``` ## Server usage On a server application, you will have to generate a secret key, and share it with the user, who will have to enter it in his own authenticator app. -<pre><code>var key = TwoStepsAuthenticator.Authenticator.GenerateKey(); -</code></pre> +```c# +var key = TwoStepsAuthenticator.Authenticator.GenerateKey(); +``` When the user will login, he will have to give you the code generated by his authenticator.<br/> You can check if the code is correct with the method CheckCode(string secret, string code).<br/> If the code is incorrect, don't log him. -<pre><code>var secret = user.secretAuthToken; +```c# +var secret = user.secretAuthToken; var code = Request.Form["code"]; var authenticator = new TwoStepsAuthenticator.TimeAuthenticator(); bool isok = authenticator.CheckCode(secret, code); -</code></pre> +``` ### Used codes manager @@ -48,17 +51,23 @@ A default implementation is provided : used codes are kept in memory for 5 minut You can define how the used codes are stored, for example if you want to handle persistence (database storage), or if you have multiple webservers.<br/> You have to implement the 2 methods of the IUsedCodesManager : -<pre><code>void AddCode(ulong challenge, string code, object user); + +```c# +void AddCode(ulong challenge, string code, object user); bool IsCodeUsed(ulong challenge, string code, object user); -</code></pre> +``` The user class must implement correctly the GetHashCode and Equals methods, because they are used to check if a specific user has used each code. When you create a new Authenticator, add the instance of your IUsedCodesManager as the first param -<pre><code>var usedCodeManager = new CustomUsedCodeManager(); + +```c# +var usedCodeManager = new CustomUsedCodeManager(); var authenticator = new TwoStepsAuthenticator.TimeAuthenticator(usedCodeManager); -</code></pre> +``` And when you check if the code is ok, you need to add the user object to the CheckCode method -<pre><code>bool isok = authenticator.CheckCode(secret, code, user); -</code></pre> + +```c# +bool isok = authenticator.CheckCode(secret, code, user); +``` |