public static bool CompareProcess(ProcessModel sample, ProcessModel process) { bool fileLengthComparison = sample.FileLength == process.FileLength ? true : false; bool initialDataComparison = BitComparer.CompareBytes(sample.InitialBytes, process.InitialBytes); return(fileLengthComparison && initialDataComparison); }
public MainResult Login(string clearTextPassword) { if (String.IsNullOrEmpty(clearTextPassword)) { return(new MainResult { ErrorMessage = "Password cannot be null", Success = false }); } bool success = true; string error = ""; try { var hashedMasterKeyResult = RetrieveHashedMasterKeyBytes(); if (!hashedMasterKeyResult.MainResult.Success) { success = false; error = hashedMasterKeyResult.MainResult.ErrorMessage; } else { byte[] hashedMasterKey = hashedMasterKeyResult.Data; byte[] hashedPassword = new SHA256Crypto().GetHashBytes(clearTextPassword); if (hashedPassword == null) { success = false; error = "An error occured during password hashing"; } else { if (!BitComparer.CompareBytes(hashedMasterKey, hashedPassword)) { success = false; error = "Login failed. Password is invalid"; } } } } catch (Exception ex) { success = false; error = ex.Message; } return(new MainResult { Success = success, ErrorMessage = error }); }