2
Check the below links:
https://www.aspsnippets.com/Articles/3639/ASPNet-Core-MVC-Encrypt-and-Decrypt-Username-or-Password-stored-in-database/
https://www.code2night.com/Blog/MyBlog/How-to-Encrypt-and-Decrypt-Password-in-Asp.Net-
1
Hello Soheb,
Here is the article links,
https://stackoverflow.com/questions/785016/best-practices-for-encrypting-and-decrypting-passwords-c-net
https://www.c-sharpcorner.com/article/encryption-and-decryption-using-a-symmetric-key-in-c-sharp/
Thanks
1
To use encryption and decryption for storing passwords in a database and then using it for login in an ASP.NET MVC application.
Here’s a simple step-by-step guide:
-
Install the necessary package: Install the System.Security.Cryptography
namespace which provides cryptographic services, including secure encoding and decoding of data.
-
Encrypt the Password: When a user is registering or changing their password, you should hash the password. Here’s a simple way to do that:
using System.Security.Cryptography;
using System.Text;
public string EncryptPassword(string password)
{
SHA256 sha256 = SHA256.Create();
byte[] bytes = Encoding.UTF8.GetBytes(password);
byte[] hash = sha256.ComputeHash(bytes);
return GetStringFromHash(hash);
}
private string GetStringFromHash(byte[] hash)
{
StringBuilder result = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
result.Append(hash[i].ToString("X2"));
}
return result.ToString();
}
-
Store the Encrypted Password: Store this hashed password in your database. Never store the plain-text password.
-
Verify the Password: When a user logs in, hash the password they enter in the same way as before, and compare it to the hashed password in your database.
public bool VerifyPassword(string enteredPassword, string storedHash)
{
string hashedPassword = EncryptPassword(enteredPassword);
return hashedPassword == storedHash;
}
Thanks

1
Hello Soheb,
When you store data on the database side, you need to encrypt the password, update that value in the password field or properties, and save the data in the database.
When the user uses the password at that time, you need to bring that password from the database, decrypt that password, and compare both values; if they match, then provide grant access; otherwise, you won't.
Here are some links for how to encrypt and decrypt things on the C# side.
https://stackoverflow.com/questions/785016/best-practices-for-encrypting-and-decrypting-passwords-c-net
https://www.c-sharpcorner.com/article/encryption-and-decryption-using-a-symmetric-key-in-c-sharp/
Thanks
0
sir can you provide any articale with Example.