# Verify a user using SMS PIN with .NET SDK This guide shows how to verify a user in a .NET application using the Verification API and .NET SDK to make and then report an SMS PIN verification. The following diagram demonstrates the flow that happens to verify a user: [![verification-flow](/assets/verification_flow.cec2857225cc33c23554c2cfa96065e34f709b3a43c726d66f19224b96b0f790.ec4a73e2.png)](/assets/verification_flow.cec2857225cc33c23554c2cfa96065e34f709b3a43c726d66f19224b96b0f790.ec4a73e2.png) 1. The end user visits your website or service and tries to log in. 2. Your backend then makes a request to the Sinch platform and [initiates an SMS PIN verification request](#initiate-your-verification-request). 3. The Sinch platform sends an SMS message with a one time PIN code to the phone number of the user. 4. The user enters the code they received. 5. Your backend makes a [report verification request](#report-your-sms-pin-code) using the code the user entered. 6. If the code matches, your backend will receive a success result from Sinch. 7. The user, now verified, can proceed to log in to your site or service. In this guide you will learn: 1. How to [set up your your Node.js app](#set-up-your-asp-net-core-application) 2. How to [initiate an SMS PIN verification request](#initiate-your-verification-request) 3. How to [report an SMS PIN verification code](#report-your-sms-pin-code) ## What you need to know before you start Before you can get started, you need the following already set up: * Set all Verification API [configuration settings](/docs/verification/getting-started). * [ASP.NET Core 7.0](https://dotnet.microsoft.com/en-us/download/) or later SDK and ASP.NET Core Runtime and a familiarity with how to create an app. * A mobile handset that can receive SMS messages. ## Set up your ASP.NET Core application Create a new project folder and open a command prompt. Execute the following command to create a new ASP.NET Core 6.0 console application: ```shell dotnet new console ``` This creates a new console application and project. The easiest way to install the SDK is using the [`dotnet` CLI](https://learn.microsoft.com/en-us/dotnet/core/install/windows?tabs=net70): 1. Open a command prompt or terminal to the local repository folder. 2. Execute the following command: ```shell dotnet add package Sinch ``` ### Modify your application In your project folder, open the `Program.cs` file and paste the provided "Program.cs" code into the file, replacing all the existing content. Program.cs using System.Text.Json; using Sinch; using Sinch.Verification.Report.Request; var sinch = new SinchClient("YOUR_access_key", "YOUR_access_secret", "YOUR_project_id"); var verification = sinch.Verification("YOUR_application_key", "YOUR_application_secret"); var id = "0"; await Query(); return; async Task Query() { Console.WriteLine( "Enter a phone number to start verification or enter the verification code to report the verification. Or enter [Q] to quit. User input: "); var input = Console.ReadLine(); if (input != null && input.StartsWith('+')) { StartVerification(input); await Query(); } else if (input is "Q") { Environment.Exit(0); } else { if (id == "0") Console.WriteLine("You must first start a verification request."); else await ReportCode(id, input); await Query(); } Console.ReadLine(); } void StartVerification(string? phoneNumber) { var response = verification.Verification.StartSms(phoneNumber).Result; id = response.Id; WriteJsonResponse(response); } async Task ReportCode(string reportId, string? code) { var response = verification.Verification.ReportSmsById(id, new ReportSmsVerificationRequest{ Sms = { Code = code } }).Result; WriteJsonResponse(response); } void WriteJsonResponse(T response) { Console.WriteLine(JsonSerializer.Serialize(response, new JsonSerializerOptions() { WriteIndented = true })); } The code provided includes placeholder parameters. You'll need to update the parameters detailed in the following subsections with your values. #### Initialize the client To start using the Verification API with the SDK, you need to initialize the main client class with your credentials from your Sinch [dashboard](https://dashboard.sinch.com) and additionally create a Verification client object that uses your [Verification app credentials](https://dashboard.sinch.com/verification/apps). Note: For testing purposes on your local environment it's fine to use hardcoded values, but before deploying to production we strongly recommend using environment variables to store the credentials. ```cpp Initialize client using Sinch; var sinch = new SinchClient("YOUR_project_id", "YOUR_access_key", "YOUR_access_secret"); var verification = sinch.Verification("YOUR_application_key", "YOUR_application_secret"); ``` Or, if you only need to use Verification API: ```cpp Initialize client for only Verification using Sinch; var sinch = new SinchClient(default, default, default); var verification = sinch.Verification("YOUR_application_key", "YOUR_application_secret"); ``` Save the file. ## Initiate your verification request 1. Now you can execute the code and initiate your verification request. Run the following command: ```shell dotnet run ``` 2. Follow the prompts in the console and enter the phone number of the mobile handset to which you want to send the SMS PIN verification request. You should receive a text message to your mobile handset with a verification code. In a production scenario, this is the code that a user would enter into your app to verify their account. You should also see the JSON response in the console. ## Report your SMS PIN code Now that you've received the SMS PIN code to your mobile handset, it's time to report that code to the Sinch servers to complete the verification process. 1. In the console, follow the prompts by entering the code you received on your mobile handset. 2. If you entered the code that you received, you should see a success report response in your console. 3. Enter `Q` in the console to quit the application or try sending a code to your mobile handset again and reporting an incorrect code to see what happens! ## Additional resources - [API specification](/docs/verification/api-reference/verification)