Files
soroush.asadi 1b3a8b493e
deploy / deploy (push) Failing after 1m21s
Rewrite: Next.js → ASP.NET Core 10 Razor Pages
Full rewrite of the portfolio site from Next.js 14 to .NET 10:

- ASP.NET Core 10 Razor Pages, no Node.js dependency
- EF Core 10 + SQLite (same schema as before — data survives upgrade)
- Cookie authentication (same single-password model)
- Resend contact form via HttpClient
- Bilingual FA/EN via locale cookie + BasePageModel
- All UI ported to Razor Pages with Tailwind CDN + custom CSS
- Vanilla JS: particles, typewriter, cursor, animations, portfolio modal
- Dockerfile: SDK 10.0-alpine → aspnet 10.0-alpine (no npm/Node needed)
- CI/CD: dropped NPM_TOKEN, ADMIN_SESSION_SECRET — pure dotnet publish

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-01 07:46:56 +03:30

38 lines
1.2 KiB
C#

using System.Security.Cryptography;
using System.Text;
namespace SoroushAsadi.Services;
/// <summary>Single-password authentication for the admin panel.</summary>
public class AuthService(IConfiguration config, IWebHostEnvironment env)
{
private string? GetPassword()
{
var pw = config["ADMIN_PASSWORD"] ?? Environment.GetEnvironmentVariable("ADMIN_PASSWORD");
if (!string.IsNullOrEmpty(pw)) return pw;
// Allow "admin" in Development only
return env.IsDevelopment() ? "admin" : null;
}
/// <summary>True when the submitted password matches the configured one (constant-time).</summary>
public bool VerifyPassword(string input)
{
var expected = GetPassword();
if (expected is null) return false;
var a = SHA256Hash(input);
var b = SHA256Hash(expected);
return CryptographicOperations.FixedTimeEquals(
Encoding.UTF8.GetBytes(a),
Encoding.UTF8.GetBytes(b));
}
public bool IsConfigured() => GetPassword() is not null;
private static string SHA256Hash(string input)
{
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(input));
return Convert.ToHexString(bytes).ToLowerInvariant();
}
}