PDA

View Full Version : hash password در سی شارپ



shahrabiamir
جمعه 05 خرداد 1402, 19:33 عصر
با سلام

برای hash password در سی شارپ از کدوم کلاس باید استفاده کرد؟

پرستو پارسایی
شنبه 06 خرداد 1402, 00:12 صبح
با سلام

برای hash password در سی شارپ از کدوم کلاس باید استفاده کرد؟


System.Security.Cryptography.SHA256Managed این کلاس برای hash کردن رمز عبور است . برای استفاده از این کلاس، می‌توانید به صورت زیر عمل کنید .
using System.Security.Cryptography;
using System.Text;


public static string HashPassword(string password)
{
using (SHA256 sha256Hash = SHA256.Create())
{
// Convert the input string to a byte array and compute the hash.
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(pass word));


// Convert the byte array to a string and return it.
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}

ShayanFiroozi
شنبه 06 خرداد 1402, 00:12 صبح
سلام ،

مطالعه کنین. (https://code-maze.com/csharp-hashing-salting-passwords-best-practices/)

و ضمنا حمایت کنین : FastLog.Net (https://github.com/ShayanFiroozi/FastLog.Net)