Otpify 1.0.4
dotnet add package Otpify --version 1.0.4
NuGet\Install-Package Otpify -Version 1.0.4
<PackageReference Include="Otpify" Version="1.0.4" />
<PackageVersion Include="Otpify" Version="1.0.4" />
<PackageReference Include="Otpify" />
paket add Otpify --version 1.0.4
#r "nuget: Otpify, 1.0.4"
#:package Otpify@1.0.4
#addin nuget:?package=Otpify&version=1.0.4
#tool nuget:?package=Otpify&version=1.0.4
🔐 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 | Versions 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. |
-
net9.0
- Microsoft.Extensions.Options (>= 9.0.7)
- SendGrid (>= 9.29.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.