Posts

Showing posts with the label Security

ASP.NET Identity Email Confirmation Token

Image
ASP.NET Identity has an Email Confirmation feature that you can (and should) enable. It will send an email with a token based Url to a registered user to simply confirm their email to allow them access into a web application. That token gets generated & stored in memory and therefore may be lost if the user does not confirm their account promptly. Code Settings Depending on the version of ASP.NET Identity the default  TokenLifespan  setting varies but the most recent version is supposed to be  24 hours  but an earlier version had it set to as low as  3 minutes.  Below is an example of how to set it directly within the  Account  controller to a 12 hour duration, you could inject the  dataProtectorProvider  via an IoC container then pass it to the constructor or just within the default  Startup.cs . public AccountController(IdentityUserManager userManager) { var dataProtectorProvider = Startup.DataProtectionProvider; ...

IIS Express Client Certificates

We recently had to investigate how to  CAC -enable a web application, one of the challenges was setting up a proper development environment to prototype & test code changes before deploying to other environments. STEP 1  - You need to have a client certificate installed on your development machine. Assuming you don't have a readily available CAC or Smart Card, you can either  create a self-signed certificate  OR for this example we just used a  corporate outlook email client certificate (used to sign & encrypt emails).   Note : The certificate should be available in your web browser. For IE go to  Internet Options > Content > Certificates  to view all your certificates. In Chrome, go to  Settings > Show advanced settings > HTTPS/SSL > Manage certificates . STEP 2  - Using Visual Studio, create a default ASP.NET MVC 5 web application. STEP 3  - Enable SSL for your project. In Visual Studio, hit  F4...

ASP.NET Identity Remember Me

ASP.NET Identity comes with a built-in Remember Me feature on the Login form, it's supposed to keep a user logged in (via an authentication cookie) for a predetermined period of time set via your code settings. However it sometimes might not work as expected and users will have to frequently log in which will cause quite a bit of frustration. Your first reaction is to modify your code then test / rinse / repeat and possibly still see the same unsuccessful results ... did you also check your website's IIS settings? Code Settings Let's first take a look at the Code configuration settings. If you create a new default MVC 5.x application in Visual Studio (with Authentication set to  Individual User Accounts ) the following code is generated (in  /App_Start/Startup.Auth.cs ): app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString("/Account/Login"), Provi...

Upgrade to ASP.NET Identity

For our first post, we'll dive into some technical challenges we encountered when upgrading our Authentication. Our site was using a custom Forms Authentication implementation before Microsoft released ASP.NET Identity 2.0. Since we recently upgraded our solution to MVC 5, we took the next step of upgrading the authentication components and benefit from the simplified 3rd party integration. If you happen to face a similar situation, use the steps below as a guideline to help you complete the upgrade .  Hope this helps! Assumptions You're using Forms Authentication with ASP.NET You've upgraded your web solution to ASP.NET MVC5+ You have a custom USER table with an Id of type integer Outline Database Add new columns to the USER table Add new tables Update EDMX or Code-First POCO for USER table only Packages Add nuget packages to your solution Configuration Add a NEW database connection string to Web.Config Remove Forms Authentication & Memb...