From d841f348b94f30cb8e94a0d34e9b20aa34d33aca Mon Sep 17 00:00:00 2001 From: Eike Rathke Date: Sat, 24 Feb 2018 14:18:04 +0100 Subject: Add ScOoxPasswordHash::verifyPassword(), tdf#104250 prep Change-Id: Ife588fa0626b01336813e956a25e51541d1096e6 --- sc/inc/tabprotection.hxx | 1 + sc/source/core/data/tabprotection.cxx | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/sc/inc/tabprotection.hxx b/sc/inc/tabprotection.hxx index 6a776807a191..f33981699b9b 100644 --- a/sc/inc/tabprotection.hxx +++ b/sc/inc/tabprotection.hxx @@ -55,6 +55,7 @@ struct ScOoxPasswordHash maHashValue.clear(); maSaltValue.clear(); } + bool verifyPassword( const OUString& aPassText ) const; }; namespace ScPassHashHelper diff --git a/sc/source/core/data/tabprotection.cxx b/sc/source/core/data/tabprotection.cxx index 6aecc83a3c11..2dec79100484 100644 --- a/sc/source/core/data/tabprotection.cxx +++ b/sc/source/core/data/tabprotection.cxx @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -88,6 +89,19 @@ ScPasswordHash ScPassHashHelper::getHashTypeFromURI(const OUString& rURI) return PASSHASH_UNSPECIFIED; } +bool ScOoxPasswordHash::verifyPassword( const OUString& aPassText ) const +{ + if (!hasPassword()) + return false; + + const OUString aHash( comphelper::Hash::calculateHashBase64( aPassText, maSaltValue, mnSpinCount, maAlgorithmName)); + if (aHash.isEmpty()) + // unsupported algorithm + return false; + + return aHash == maHashValue; +} + ScPassHashProtectable::~ScPassHashProtectable() { } -- cgit