hash - Hashing passwords with MD5 or sha-256 C# -


i'm writing register form application still having problems being new c#.

i looking encrypt/hash passwords md5 or sha-256, preferably sha-256.

any examples? want able take information "string password;" , hash , store in variable "string hpassword;". ideas?

don't use simple hash, or salted hash. use sort of key-strengthening technique bcrypt (with .net implementation here) or pbkdf2 (with built-in implementation).

here's example using pbkdf2.

to generate key password...

string password = getpasswordfromuserinput();  // specify want randomly generate 20-byte salt using (var derivebytes = new rfc2898derivebytes(password, 20)) {     byte[] salt = derivebytes.salt;     byte[] key = derivebytes.getbytes(20);  // derive 20-byte key      // save salt , key database } 

and test if password valid...

string password = getpasswordfromuserinput();  byte[] salt, key; // load salt , key database  using (var derivebytes = new rfc2898derivebytes(password, salt)) {     byte[] newkey = derivebytes.getbytes(20);  // derive 20-byte key      if (!newkey.sequenceequal(key))         throw new invalidoperationexception("password invalid!"); } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -