Set Up a Two Factor Authentication with SMS.

Similar documents
Description: This feature will enable user to send messages from website to phone number.

How to read/write text file

dotnetexample Release 0.1

CSC 415 ONLINE PHOTOALBUM: THE SEQUEL ASP.NET VERSION

Advanced ASP.NET Identity. Brock Allen

Requirement Document v1.2 WELCOME TO CANLOG.IN. API-Key Help Document. Version SMS Integration Document

Entity Configuration Configure the account entity in D365 with fields to hold the cloud agreement status. Two Value OptionSet

Consuming SAIT API via ITS ESB from web / desktop application

LAMPIRAN. 1. Source Code Data Buku. using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.

Main Game Code. //ok honestly im not sure, if i guess its a class ment for this page called methodtimer that //either uses the timer or set to timer..

emkt Browserless Coding For C#.Net and Excel

Design and Implementation of Real Time Bi-directional Traffic Management Support System with GPS and WebSocket

Introduction to ASP.NET Identity. Brock Allen

For your convenience Apress has placed some of the front matter material after the index. Please use the Bookmarks and Contents at a Glance links to

REST Admin API. Note: Version 9.X or higher is required for the support of REST API. Version /17

The contents of this document are directly taken from the EPiServer SDK. Please see the SDK for further technical information about EPiServer.

COOKBOOK Sending an in Response to Actions

Capstone Database Management

Using CSE Cisco Anyconnect with 2FA

Apex TG India Pvt. Ltd.

Brain Corporate Bulk SMS

RegEx-validate IP address. Defined below is the pattern for checking an IP address with value: String Pattern Explanation

GSU Alumni Portal. OPUS Open Portal to University Scholarship. Governors State University. Vemuri Vinusha Chowdary Governors State University

MVC - Repository-And-Unit-Of-Work

Configuration Web Services for.net Framework

LIPNET OUTBOUND API FORMS DOCUMENTATION

API Guide MSS-8 and MVS-16

Activating AspxCodeGen 4.0

IST311 Chapter13.NET Files (Part2)

Integrate WebScheduler to Microsoft SharePoint 2007

SETTING UP YOUR.NET DEVELOPER ENVIRONMENT

SETTING UP YOUR.NET DEVELOPER ENVIRONMENT

GetMetadata() Verify() Publish() Build a Custom Adapter Setup Create a service adapter GetMetadata()...

To start we will be using visual studio Start a new C# windows form application project and name it motivational quotes viewer

Composer Help. Web Request Common Block

LEARN HOW TO USE CA PPM REST API in 2 Minutes!

Create The Internet of Your Things

ICE CLEAR EUROPE DMS GLOBAL ID CREATION USER GUIDE VERSION 1.0

We currently are able to offer three different action types:

USER GUIDE Conversion and Validation of User Input

PULSE - API. The purpose of this document is to provide example requests and responses for all relevant Pulse services requests

CHAPTER 1: INTRODUCING C# 3

Getting Started with the Bullhorn SOAP API and C#/.NET

File Handling Programming 1 C# Programming. Rob Miles

ExtraHop 7.3 ExtraHop Trace REST API Guide

Introduction to IdentityServer

RegEx - Numbers matching. Below is a sample code to find the existence of integers within a string.

Chapter 14: Files and Streams

Accessing the Progress OpenEdge AppServer. From Progress Rollbase. Using Object Script

Starting with FRITZ!OS 5.50 a session ID is also required in all three cases.

GENESIS64 Using IRepository to Access Configuration Databases

MapItFast REST API. Table of Contents

Files and Streams. Today you will learn. Files and Web Applications File System Information Reading and Writing with Streams Allowing File Uploads

KWizCom Corporation. imush. Information Management Utilities for SharePoint. Printing Feature. Application Programming Interface (API)

Console.ReadLine(); }//Main

Using Voodoo SMS within Zapier

BULK HTTP API DOCUMENTATION

Appendix A Programkod

User Directories. Overview, Pros and Cons

Microsoft Cloud Workshops. Modern Cloud Apps Learner Hackathon Guide

Credential Policy CHAPTER

API Documentation. Release Version 1 Beta

EXAM Web Development Fundamentals. Buy Full Product.

Software Development Kit. User Guide

The Merit Palk API allows 3rd party developers to expand and build on the Merit Palk platform.

Syncfusion Report Platform. Version - v Release Date - March 22, 2017

Nortridge Loan System

CSC 355 PROJECT 4 NETWORKED TIC TAC TOE WITH WPF INTERFACE

RESTful API SecurAccess RESTful API Guide

From the 8th of April 2011, Blue Chip s SMS service will be provided by MessageNet.

Configuring Pentaho with Integrated Windows Authentication (IWA)

PeoplePassword Documentation v6.0

Melon, Inc. Melon Components Starter Kit

NIELSEN API PORTAL USER REGISTRATION GUIDE

Creating SDK plugins

Shopitem API A technical guide to the REST API for managing updates of shopitems

C# Data Manipulation

EBULKSMS

Probid B2B programmer guide

External HTTPS Trigger AXIS Camera Station 5.06 and above

Annex B: Prototype Draft Model Code. April 30 th, 2015 Siamak Khaledi, Ankit Shah, Matthew Shoaf

Web services CSCI 470: Web Science Keith Vertanen Copyright 2014

Merchant Toolkit. Multi-Factor Authentication

C# Data Manipulation

Drop Windows Login Sql Server 2005 Connection String In Web.config

ArcGIS for Server Administration API for C# Developers. Philip

CSIS 1624 CLASS TEST 6

Writing Your First Autodesk Revit Model Review Plug-In

WebDAV Configuration

Table of Contents Web Service Specification (version 1.5)

Low-level CMS Security and Custom Providers

TMail Temporary Multi Domain System. API Documentation. TMail Temporary Multi Domain System. By Harshit Peer

SMITE API Developer Guide TABLE OF CONTENTS

Authentify SMS Gateway

CSC Web Technologies, Spring Web Data Exchange Formats

DIRECTOR, MEMBER SERVICES

INSTRUCTIONS FOR CREATING YOUR FBBE ACCOUNT

Tyler Identity User Account Management New World ERP Foundation

3-tier Architecture Step by step Exercises Hans-Petter Halvorsen

PERFORMANCE HORIZON PUBLISHER API INTRODUCTION

Transcription:

Set Up a Two Factor Authentication with SMS. Adding two-factor authentication (2FA) to your web application increases the security of your user's data. 1. First we validate the user with an email and password 2. Second we validate the user using his or her mobile device, by sending a onetime verification code SMS. Web.config Settings: <add key="didnumber" value="16505340986"/> <add key="apikey" value="your_api_key"/> <add key="smsapibaseurl" value="https://api.didforsale.com/didforsaleapi/index.php/api/sms/send/"/> Using DIDforSale API for send verification code. Code: DID2FA\App_Start\IdentityConfig.cs using System; using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Security.Claims; using System.Threading.Tasks; using System.Web; using Microsoft.AspNet.Identity; using Microsoft.AspNet.Identity.EntityFramework; using Microsoft.AspNet.Identity.Owin; using Microsoft.Owin; using Microsoft.Owin.Security; using DID2FA.Models; using System.Web.Configuration; using System.Net; using System.IO; namespace DID2FA public class EmailService : IIdentityMessageService public Task SendAsync(IdentityMessage message) // Plug in your email service here to send an email. return Task.FromResult(0);

public class SmsService : IIdentityMessageService public string didnumber = WebConfigurationManager.AppSettings["DidNumber"].ToString(); public string apikey = WebConfigurationManager.AppSettings["ApiKey"].ToString(); public string smsapibaseurl = WebConfigurationManager.AppSettings["SmsApiBaseUrl"].ToString(); public Task SendAsync(IdentityMessage message) string result = string.empty; //DIDforsale api only accept json data format ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 SecurityProtocolType.Tls12 SecurityProtocolType.Tls11 SecurityProtocolType.Tls; var httpwebrequest = (HttpWebRequest)WebRequest.Create(smsApiBaseUrl + apikey); httpwebrequest.contenttype = "application/json"; httpwebrequest.method = "POST"; using (var streamwriter = new StreamWriter(httpWebRequest.GetRequestStream())) var json = "\"from\":\"" + didnumber + "\",\"to\":[\"" + message.destination + "\"],\"text\":\"" + message.body + "\""; streamwriter.write(json); streamwriter.flush(); streamwriter.close(); var httpresponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamreader = new StreamReader(httpResponse.GetResponseStream())) result = streamreader.readtoend(); return Task.FromResult(0); // Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application. public class ApplicationUserManager : UserManager<ApplicationUser> public ApplicationUserManager(IUserStore<ApplicationUser> store) : base(store) public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context) var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>())); // Configure validation logic for usernames manager.uservalidator = new UserValidator<ApplicationUser>(manager) AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true ;

// Configure validation logic for passwords manager.passwordvalidator = new PasswordValidator RequiredLength = 6, RequireNonLetterOrDigit = true, RequireDigit = true, RequireLowercase = true, RequireUppercase = true, ; // Configure user lockout defaults manager.userlockoutenabledbydefault = true; manager.defaultaccountlockouttimespan = TimeSpan.FromMinutes(5); manager.maxfailedaccessattemptsbeforelockout = 5; // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user // You can write your own provider and plug it in here. manager.registertwofactorprovider("phone Code", new PhoneNumberTokenProvider<ApplicationUser> MessageFormat = "Your security code is 0" ); manager.registertwofactorprovider("email Code", new EmailTokenProvider<ApplicationUser> Subject = "Security Code", BodyFormat = "Your security code is 0" ); manager.emailservice = new EmailService(); manager.smsservice = new SmsService(); var dataprotectionprovider = options.dataprotectionprovider; if (dataprotectionprovider!= null) manager.usertokenprovider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity")); return manager; // Configure the application sign-in manager which is used in this application. public class ApplicationSignInManager : SignInManager<ApplicationUser, string> public ApplicationSignInManager(ApplicationUserManager usermanager, IAuthenticationManager authenticationmanager) : base(usermanager, authenticationmanager) user) public override Task<ClaimsIdentity> CreateUserIdentityAsync(ApplicationUser return user.generateuseridentityasync((applicationusermanager)usermanager);

public static ApplicationSignInManager Create(IdentityFactoryOptions<ApplicationSignInManager> options, IOwinContext context) return new ApplicationSignInManager(context.GetUserManager<ApplicationUserManager>(), context.authentication); Code description: Fetch required values from web.config. public string didnumber = WebConfigurationManager.AppSettings["DidNumber"].ToString(); public string apikey = WebConfigurationManager.AppSettings["ApiKey"].ToString(); public string smsapibaseurl = WebConfigurationManager.AppSettings["SmsApiBaseUrl"].ToString(); Send verification code to number via DIDforSale string result = string.empty; //DIDforsale api only accept json data format ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 SecurityProtocolType.Tls12 SecurityProtocolType.Tls11 SecurityProtocolType.Tls; var httpwebrequest = (HttpWebRequest)WebRequest.Create(smsApiBaseUrl + apikey); httpwebrequest.contenttype = "application/json"; httpwebrequest.method = "POST"; using (var streamwriter = new StreamWriter(httpWebRequest.GetRequestStream())) var json = "\"from\":\"" + didnumber + "\",\"to\":[\"" + message.destination + "\"],\"text\":\"" + message.body + "\""; streamwriter.write(json); streamwriter.flush(); streamwriter.close(); var httpresponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamreader = new StreamReader(httpResponse.GetResponseStream())) result = streamreader.readtoend(); Use above code to send SMS to register number using didforsale api. // Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verification of the user // You can write your own provider and plug it in here.

manager.registertwofactorprovider("phone Code", new PhoneNumberTokenProvider<ApplicationUser> MessageFormat = "Your security code is 0" ); Take a sample application in visual studio and enable Two factor authentication. And add a phone number then you need to check above code and update it accordingly.