From f4efea784962e35311000fdc50df46b6e81e6856 Mon Sep 17 00:00:00 2001 From: tarek_saidi Date: Mon, 13 Nov 2006 20:03:15 +0000 Subject: [PATCH] show key dialog again if hash test fails git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@116 b624d157-de02-0410-bad0-e51aec6abb33 --- src/Database.h | 1 + src/StandardDatabase.cpp | 12 +++++++++++- src/StandardDatabase.h | 2 ++ src/mainwindow.cpp | 3 +++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Database.h b/src/Database.h index 9e85d0a..f84c42b 100644 --- a/src/Database.h +++ b/src/Database.h @@ -394,6 +394,7 @@ public: \return TRUE if the creation was successfull, otherwise FALSE. */ virtual bool createKeyFile(const QString& filename,int length=32, bool Hex=false)=0; + virtual bool isKeyError()=0; }; class IKdbSettings{ diff --git a/src/StandardDatabase.cpp b/src/StandardDatabase.cpp index a41fc42..0c39dad 100644 --- a/src/StandardDatabase.cpp +++ b/src/StandardDatabase.cpp @@ -421,6 +421,7 @@ SHA256::hashBuffer(buffer+DB_HEADER_SIZE,FinalKey,crypto_size); if(memcmp(ContentsHash, FinalKey, 32) != 0){ error=tr("Hash test failed.\nThe key is wrong or the file is damaged."); + KeyError=true; return false;} unsigned long tmp_id=0; @@ -1359,7 +1360,16 @@ void StandardDatabase::create(){ RootGroup.Handle=NULL; Algorithm=Rijndael_Cipher; KeyTransfRounds=6000; - + KeyError=false; +} + +bool StandardDatabase::isKeyError(){ + if(KeyError){ + KeyError=false; + return true; + } + else + return false; } IEntryHandle* StandardDatabase::cloneEntry(const IEntryHandle* entry){ diff --git a/src/StandardDatabase.h b/src/StandardDatabase.h index 8ade8e2..cc8d47f 100644 --- a/src/StandardDatabase.h +++ b/src/StandardDatabase.h @@ -146,6 +146,7 @@ public: virtual int numEntries(); virtual int numGroups(); virtual QString getError(); + virtual bool isKeyError(); virtual void cleanUpHandles(); virtual QPixmap& icon(int index); virtual int numIcons(); @@ -227,6 +228,7 @@ private: QListCustomIcons; QFile* File; QString error; + bool KeyError; QList UnknownMetaStreams; unsigned int KeyTransfRounds; CryptAlgorithm Algorithm; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 22a9b47..65d4999 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -336,11 +336,14 @@ void KeepassMainWindow::openDatabase(QString filename,bool IsAuto){ else{ StatusBarGeneral->setText(tr("Loading Failed")); QString error=db->getError(); + bool KeyError=auth->isKeyError(); delete db; if(error==QString())error=tr("Unknown error while loading database."); QMessageBox::critical(this,tr("Error") ,tr("The following error occured while opening the database:\n%1") .arg(error),tr("OK")); + if(KeyError) + openDatabase(filename,IsAuto); } StatusBarGeneral->setText(tr("Ready")); }