Here's an example code snippet for creating a salted hash of a string in C#:
main.cs1249 chars49 lines
This code generates a random salt, then uses the Rfc2898DeriveBytes class with 10000 iterations to compute a hash of the input string and the salt. The resulting hash can be stored in a database or other storage medium, while the salt can be kept alongside it. Later, when a user tries to log in with their password, the same salt can be retrieved and the hash can be computed again to check if it matches the stored hash. This adds an extra layer of security, as even if an attacker gains access to the hash, they would still need the salt and the iteration count in order to crack the password.
gistlibby LogSnag