Monday, July 22, 2024
HomeC#Customized Password Hash With Salt Key – CSharpnet

Customized Password Hash With Salt Key – CSharpnet

Asp.web Id Present Default password hash, however now we’ll see that the best way to create customized password hash with salt key utilizing crypto class which supplied by Asp.Internet Framework.

namespace of crypto class is


“Crypto” class by default there in Net Utility however if you wish to use this in Console or Window software then obtain it from Nuget Package deal Supervisor search : System.Net.Helpers.Crypto

now lets see how its works :

Crypto class encryption


string password = "Welcome@123"; // pattern password
string salt = Crypto.GenerateSalt(); // salt key
password = password + salt;
string hashedPassword = Crypto.HashPassword(password);

retailer this generated hashedPassword and salt in database. on the time of verification it is advisable get salt key and hashed password from database after which confirm entered password utilizing VerifyHashedPassword technique.

see instance beneath:

// First parameter is the beforehand hashed string utilizing a Salt
string salt = "agftwjd128"; //learn from database
string HashedPass = "cbdr45/shdysndys"; //learn from database
string PlainPass= "Welcome@123";
PlainPass = PlainPass + salt; // append salt key
bool outcome = Crypto.VerifyHashedPassword(HashedPass, PlainPass); //confirm password

Crypto class has different strategies :


these all technique might be use for encryption however ideally you shouldn’t for password as a result of suppose you might have entered “Welcome@123” as password then it would generate the identical encrypted string for password, nevertheless Crypto.HashPassword() generate new encrypted string for a similar password, so whether or not it’s totally different or identical password it would generate new Encrypted string each time.

Output will seem like this:

Conclusion :

One of the simplest ways to encrypt password is encrypt utilizing HashPassword appending salt key to it make it safer, as soon as its encrypted it’s not possible to transform again to plain password.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments