mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 13:03:12 +00:00
Forgot Password answers every address the same way and emails a code only to an active account. Codes are stored as salted SHA-256 hashes, expire 15 minutes after issue, are replaced by a newer request, and are checked only against the email they were issued to. Five failed checks delete the code; attempts are reserved with one conditional UPDATE so concurrent guesses cannot exceed the budget. VerificationCode requires the email, and email and code are accepted in the JSON body so they stay out of URLs. The three anonymous endpoints are rate limited to 10 requests per 15 minutes per client IP. Forwarded headers are trusted only through loopback and private hops, since the API sits behind the EB load balancer and nginx. The migration adds hash, salt, expiry and attempt columns and deletes the old plaintext rows.
34 lines
1 KiB
C#
34 lines
1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Data.SeaHavenIndustries
|
|
{
|
|
public class ForgetPasswordCode
|
|
{
|
|
public int Id { get; set; }
|
|
public string UserId { get; set; }
|
|
public string Email { get; set; }
|
|
|
|
/// <summary>
|
|
/// Legacy plaintext column. It is always written empty; only
|
|
/// <see cref="CodeHash"/> is compared.
|
|
/// </summary>
|
|
public string Code { get; set; } = string.Empty;
|
|
|
|
/// <summary>Lowercase hex SHA-256 of "<see cref="CodeSalt"/>:code".</summary>
|
|
[MaxLength(64)]
|
|
public string CodeHash { get; set; } = string.Empty;
|
|
|
|
[MaxLength(32)]
|
|
public string CodeSalt { get; set; } = string.Empty;
|
|
|
|
public DateTime ExpiresAtUtc { get; set; }
|
|
|
|
/// <summary>Checks consumed against this code, including concurrent ones still in flight.</summary>
|
|
public int FailedAttempts { get; set; }
|
|
}
|
|
}
|