Add password hashing, user settings with 2FA, and project image lightbox.
Hardens auth with PBKDF2, lockouts, local QR setup, and safer embeds while moving account security under the username menu.
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Web.Security;
|
||||
|
||||
namespace atakanozbancom.Models.classes
|
||||
{
|
||||
public static class SecretProtector
|
||||
{
|
||||
private static readonly string[] Purposes = { "atakanozbancom.TotpSecret.v1" };
|
||||
|
||||
public static string Protect(string plaintext)
|
||||
{
|
||||
if (string.IsNullOrEmpty(plaintext))
|
||||
return plaintext;
|
||||
|
||||
var bytes = Encoding.UTF8.GetBytes(plaintext);
|
||||
var protectedBytes = MachineKey.Protect(bytes, Purposes);
|
||||
return Convert.ToBase64String(protectedBytes);
|
||||
}
|
||||
|
||||
public static string Unprotect(string protectedValue)
|
||||
{
|
||||
if (string.IsNullOrEmpty(protectedValue))
|
||||
return protectedValue;
|
||||
|
||||
try
|
||||
{
|
||||
var protectedBytes = Convert.FromBase64String(protectedValue);
|
||||
var bytes = MachineKey.Unprotect(protectedBytes, Purposes);
|
||||
return bytes == null ? null : Encoding.UTF8.GetString(bytes);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool LooksProtected(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
var bytes = Convert.FromBase64String(value);
|
||||
return bytes.Length > 16;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user