Check password is correct by checking hash

Handle failures gracefully

Change-Id: Ifb6da8c11a86c50fb11964c18cc1be1326461f78
diff --git a/Ext4Crypt.cpp b/Ext4Crypt.cpp
index df163b4..0c7b351 100644
--- a/Ext4Crypt.cpp
+++ b/Ext4Crypt.cpp
@@ -313,7 +313,18 @@
     unsigned char master_key[key_length / 8];
     if (cryptfs_get_master_key (&ftr, password, master_key)){
         SLOGI("Incorrect password");
-        return -1;
+        ftr.failed_decrypt_count++;
+        if (put_crypt_ftr_and_key(ftr, key_props)) {
+            SLOGW("Failed to update failed_decrypt_count");
+        }
+        return ftr.failed_decrypt_count;
+    }
+
+    if (ftr.failed_decrypt_count) {
+        ftr.failed_decrypt_count = 0;
+        if (put_crypt_ftr_and_key(ftr, key_props)) {
+            SLOGW("Failed to reset failed_decrypt_count");
+        }
     }
 
     s_key_store[path] = keys{std::string(reinterpret_cast<char*>(master_key),