Tag:blog algorithm for io .net new
public static string Hashpassword (string password) {if (password = = null) { throw new ArgumentNullException ("password"); } byte[] Salt; byte[] bytes; using (rfc2898derivebytes rfc2898derivebytes = new Rfc2898derivebytes (password, +,)) {sal t = Rfc2898derivebytes.salt; bytes = Rfc2898derivebytes.getbytes (32); } byte[] array = new byte[49]; Buffer.blockcopy (salt, 0, array, 1, 16); Buffer.blockcopy (bytes, 0, array, 17, 32); return convert.tobase64string (array); public static bool Verifyhashedpassword (string Hashedpassword, string password) {if (Hashedpas Sword = = null) {return false; } if (password = = null) {throw new ArgumentNullException ("password"); } byte[] ArRay = convert.frombase64string (Hashedpassword); if (array. Length! = 49 | | ARRAY[0]! = 0) {return false; } byte[] Array2 = new BYTE[16]; Buffer.blockcopy (array, 1, array2, 0, 16); byte[] Array3 = new BYTE[32]; Buffer.blockcopy (array, n, array3, 0, 32); byte[] bytes; using (rfc2898derivebytes rfc2898derivebytes = new Rfc2898derivebytes (password, array2, 1000)) { bytes = Rfc2898derivebytes.getbytes (32); } return bytearraysequal (Array3, bytes); } private static bool Bytearraysequal (byte[] A, byte[] b) {if (object. ReferenceEquals (A, B)) {return true; if (a = = NULL | | b = NULL | | A.length! = b.length) {return false; } bool flag = TRUE; for (int i = 0; i < a.length; i++) { Flag &= (A[i] = = B[i]); } return flag; }