Two Factor Authentication

Google authenticator

Using Google Authentication

Have you ever needed to use Google Authentication, but for whatever reason, you could not use the entity framework. This blog shows how to do just that but use ADO.Net with stored procedures.

The blog will also show you how to encrypt user emails and store them in your database. I will show you two ways of doing this, one using Effortless.Net.Encryption a Nuget package and then use ProtectedData Class which can be found in the System.Security.Cryptography namespace under the System.Security Assembly.

The blog will also show how to create a cookie using Owin that only allow visitors to view sections of your site when they have logged in.

The first thing that we need to do is create a project in Visual Studio, and then add the class libraries that the project will require.

For this example, I have created the following class libraries:

  • Web.Domain
  • Web.Model
  • Web.Security
  • Web.UI, MVC project

I then added the following packages that I required.

For this project, I used:

  • Effortless.Net.Encryption
  • Owin
  • Microsoft.Owin
  • Microsoft.Owin.Host.SystemWeb
  • Microsoft.Owin.Security
  • Microsoft.Owin.Security.Cookies
  • Microsoft.Owin.Security.OAuth
  • Ninject.Web.Mvc
  • Ninject.Web.Common
  • Ninject

Once everything is set up, I created the model for the site.

Once the models have been created, we now need to create the Controllers for the site. For this example, I had three:

  • HomeController
  • AccountController
  • BaseController

I will only show the code for the account and base controller as the home controller only displays the home page.


Once the models have been created, we now need to create the Controllers for the site. For this example, I had three:

  • HomeController
  • AccountController
  • BaseController

I will only show the code for the account and base controller as the home controller only displays the home page.


Summary

So far I have shown you the models for the site and controllers, in the next blog, I will show you how to pass the data to the database and encrypt the email and hash the password.

If you have any queries, please use the form below.

Thanks for reading.

Leave a comment

*
*