how to use encrypted and decrypted Password for storing in databse and after that use it for login using Asp.net MVC.
Loading
how to use encrypted and decrypted Password for storing in databse and after that use it for login using Asp.net MVC.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tural SuleymaniRank #211 · 11.5K reputationPosted May 8, 2024, 3:17 PM EDT
Encryption: Encrypt the password before storing it in the database. You can use cryptographic hashing algorithms like bcrypt, PBKDF2, or SHA-256. ASP.NET provides built-in support for hashing passwords using the
System.Security.Cryptographynamespace.Storage: Store the encrypted password in your database. Make sure the field in your database table is large enough to accommodate the encrypted password.
Login: When a user attempts to log in, you hash the provided password and compare it with the stored, encrypted password in the database. If the hashes match, the passwords match.
Amit MohantyRank #112 · 20K reputationPosted May 9, 2024, 2:15 AM EDT
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-
Jaimin ShethiyaRank #177 · 13.7K reputationPosted May 9, 2024, 12:23 AM EDT
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
Soheb AhmadRank #9,376 · 207 reputationPosted May 9, 2024, 12:24 AM EDT
sir can you provide any articale with Example.
Naimish MakwanaRank #324 · 7.7K reputationPosted May 9, 2024, 12:37 AM EDT
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.Cryptographynamespace 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
Jaimin ShethiyaRank #177 · 13.7K reputationPosted May 9, 2024, 2:38 AM EDT
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