Otpify 1.0.4

dotnet add package Otpify --version 1.0.4
                    
NuGet\Install-Package Otpify -Version 1.0.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Otpify" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Otpify" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="Otpify" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Otpify --version 1.0.4
                    
#r "nuget: Otpify, 1.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Otpify@1.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Otpify&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=Otpify&version=1.0.4
                    
Install as a Cake Tool

🔐 Otpify

Otpify is a lightweight and developer-friendly .NET library for generating, sending, and verifying One-Time Passwords (OTPs) via SendGrid email service.

Ideal for authentication workflows like login, signup, and password recovery in your .NET apps.


📦 Installation

Install via NuGet:

dotnet add package Otpify

🚀 Quick Start & Usage

Step 1: Configure Options

var options = new OtpOptions
{
    SendGridApiKey = "YOUR_SENDGRID_API_KEY",        // Your SendGrid API Key
    OtpLength = 6,                                   // Length of the OTP
    ExpiryMinutes = 5,                               // Expiry duration in minutes
    EmailTemplatePath = "Templates/CustomTemplate.html", // HTML Template path
    FromEmail = "support@yourdomain.com",            // Sender Email
    FromName = "Otpify"                              // Sender Name
};

Step 2: Create OtpVerifier Instance

var otpService = OtpVerifier.Create(options);

Step 3: Send OTP to User

await otpService.SendOtpAsync("user@example.com");

Step 4: Verify OTP

bool isValid = otpService.VerifyOtp("123456");

if (isValid)
{
    Console.WriteLine("✅ OTP verified!");
}
else
{
    Console.WriteLine("❌ OTP invalid or expired.");
}

💌 Email Template (HTML)

Create an HTML file at the specified path (e.g., Templates/CustomTemplate.html):

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
</head>
<body>
  <h2>Hello {{Email}},</h2>
  <p>Your OTP is:</p>
  <h1>{{OTP}}</h1>
  <p>This OTP is valid for 5 minutes.</p>
</body>
</html>

📝 Placeholders like {{Email}} and {{OTP}} will be replaced dynamically.


📂 .csproj Setup

Ensure your .csproj file includes the template:

<ItemGroup>
  <Content Include="Templates\CustomTemplate.html">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>

Also add required packages:

<ItemGroup>
  <PackageReference Include="Microsoft.Extensions.Options" Version="9.0.7" />
  <PackageReference Include="SendGrid" Version="9.29.3" />
</ItemGroup>

✅ Full Working Example

var options = new OtpOptions
{
    SendGridApiKey = "SG.xxxxxxxx",
    OtpLength = 6,
    ExpiryMinutes = 5,
    EmailTemplatePath = "Templates/CustomTemplate.html",
    FromEmail = "support@yourdomain.com",
    FromName = "Otpify"
};

var otpService = OtpVerifier.Create(options);

// Step 1: Send OTP
await otpService.SendOtpAsync("user@example.com");

// Step 2: Ask user to enter OTP...

// Step 3: Verify OTP
bool isVerified = otpService.VerifyOtp("123456");

Console.WriteLine(isVerified ? "OTP Verified!" : "OTP Invalid or Expired!");

📄 License

This project is licensed under the MIT License.


👨‍💻 Author

Made with ❤️ by Ritik Sharma 📧 dev.reetik@gmail.com

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4 138 8/1/2025
1.0.3 122 8/1/2025
1.0.2 119 8/1/2025
1.0.1 110 8/1/2025
1.0.0 120 8/1/2025