summaryrefslogtreecommitdiff
path: root/cui
diff options
context:
space:
mode:
authorSarper Akdemir <sarper.akdemir.extern@allotropia.de>2023-11-08 07:36:52 +0300
committerSarper Akdemir <sarper.akdemir.extern@allotropia.de>2023-11-15 19:48:38 +0100
commitcdcff8c34144e883eca9dc6e1a85968ed34909c2 (patch)
tree3e976e02a3b3b43aa7962850b07efad63f5f25b1 /cui
parent51d9c9899f54200a2bf9bf49df16c03cca403498 (diff)
tdf#157518: add password strength meter to setmasterpassworddlg
Moves PasswordStrength bits that provide utility functions from cui to svl, merging them with PasswordHelper there. Adds password strength bar for the set master password dialog. (accessible via Tools -> Options -> LibreOffice -> Security -> Passwords for Web Connections) Change-Id: I8dc1090a041f8388c2e139beb1d0d9a0beb8acb0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159370 Tested-by: Jenkins Reviewed-by: Sarper Akdemir <sarper.akdemir.extern@allotropia.de>
Diffstat (limited to 'cui')
-rw-r--r--cui/Library_cui.mk3
-rw-r--r--cui/source/dialogs/passwdomdlg.cxx13
-rw-r--r--cui/source/inc/PasswordStrength.hxx28
-rw-r--r--cui/source/util/PasswordStrength.cxx48
4 files changed, 8 insertions, 84 deletions
diff --git a/cui/Library_cui.mk b/cui/Library_cui.mk
index 4a41c10baa2c..e122d2b734c4 100644
--- a/cui/Library_cui.mk
+++ b/cui/Library_cui.mk
@@ -71,13 +71,11 @@ $(eval $(call gb_Library_use_externals,cui,\
boost_headers \
$(call gb_Helper_optional,OPENCL,\
clew) \
- icui18n \
icuuc \
icu_headers \
libxml2 \
orcus-parser \
orcus \
- zxcvbn-c \
zxing \
))
@@ -244,7 +242,6 @@ $(eval $(call gb_Library_add_exception_objects,cui,\
cui/source/tabpages/tptrans \
cui/source/tabpages/transfrm \
cui/source/util/FontFeatures \
- cui/source/util/PasswordStrength \
cui/source/dialogs/widgettestdlg \
))
diff --git a/cui/source/dialogs/passwdomdlg.cxx b/cui/source/dialogs/passwdomdlg.cxx
index 189738b45e3c..a7e95a29f3b4 100644
--- a/cui/source/dialogs/passwdomdlg.cxx
+++ b/cui/source/dialogs/passwdomdlg.cxx
@@ -18,10 +18,10 @@
*/
#include <sfx2/objsh.hxx>
+#include <svl/PasswordHelper.hxx>
#include <vcl/svapp.hxx>
#include <officecfg/Office/Common.hxx>
#include <passwdomdlg.hxx>
-#include <PasswordStrength.hxx>
#include <strings.hrc>
#include <dialmgr.hxx>
@@ -41,14 +41,16 @@ IMPL_LINK_NOARG(PasswordToOpenModifyDialog, OkBtnClickHdl, weld::Button&, void)
{
if (m_oPasswordPolicy)
{
- if (!passwordCompliesPolicy(m_xPasswdToOpenED->get_text().toUtf8().getStr()))
+ if (!SvPasswordHelper::PasswordMeetsPolicy(m_xPasswdToOpenED->get_text(),
+ m_oPasswordPolicy))
{
m_xPasswdToOpenED->grab_focus();
return;
}
if (m_xOpenReadonlyCB->get_active()
- && !passwordCompliesPolicy(m_xPasswdToModifyED->get_text().toUtf8().getStr()))
+ && !SvPasswordHelper::PasswordMeetsPolicy(m_xPasswdToModifyED->get_text(),
+ m_oPasswordPolicy))
{
m_xPasswdToModifyED->grab_focus();
return;
@@ -115,7 +117,8 @@ IMPL_LINK(PasswordToOpenModifyDialog, ChangeHdl, weld::Entry&, rEntry, void)
}
assert(pIndicator);
- bool bPasswordMeetsPolicy = passwordCompliesPolicy(aPasswordText.toUtf8().getStr());
+ bool bPasswordMeetsPolicy
+ = SvPasswordHelper::PasswordMeetsPolicy(aPasswordText, m_oPasswordPolicy);
if (pLevelBar)
{
rEntry.set_message_type(bPasswordMeetsPolicy ? weld::EntryMessageType::Normal
@@ -126,7 +129,7 @@ IMPL_LINK(PasswordToOpenModifyDialog, ChangeHdl, weld::Entry&, rEntry, void)
// if password doesn't meet policy cap the percentage at 70%
if (pLevelBar)
pLevelBar->set_percentage(
- std::min(getPasswordStrengthPercentage(aPasswordText.toUtf8().getStr()),
+ std::min(SvPasswordHelper::GetPasswordStrengthPercentage(aPasswordText),
bPasswordMeetsPolicy ? std::numeric_limits<double>::max() : 70.0));
if (m_nMaxPasswdLen)
diff --git a/cui/source/inc/PasswordStrength.hxx b/cui/source/inc/PasswordStrength.hxx
deleted file mode 100644
index e8c9e86a83cb..000000000000
--- a/cui/source/inc/PasswordStrength.hxx
+++ /dev/null
@@ -1,28 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-/** Get password strength percentage
-
- Maps the received password entropy bits to password strength percentage.
- 0 bits -> 0%
- >= 112 bits -> 100%
-
- @param pPassword null terminated password string.
- @returns Password strength percentage in the range [0.0, 100.0]
-*/
-double getPasswordStrengthPercentage(const char* pPassword);
-
-/** Checks if the password meets the password policies
-
- @param pPassword null terminated password string.
- @returns true if password meets the policy or there is no policy enforced.
-*/
-bool passwordCompliesPolicy(const char* pPassword);
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/cui/source/util/PasswordStrength.cxx b/cui/source/util/PasswordStrength.cxx
deleted file mode 100644
index 678ad2f74e76..000000000000
--- a/cui/source/util/PasswordStrength.cxx
+++ /dev/null
@@ -1,48 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-
-#include <PasswordStrength.hxx>
-#include <officecfg/Office/Common.hxx>
-#include <unicode/regex.h>
-#include <unicode/unistr.h>
-#include <unicode/errorcode.h>
-#include <sal/log.hxx>
-#include <zxcvbn.h>
-
-double getPasswordStrengthPercentage(const char* pPassword)
-{
- static constexpr double fMaxStrengthBits = 112.0;
- return std::min(100.0, ZxcvbnMatch(pPassword, nullptr, nullptr) * 100.0 / fMaxStrengthBits);
-}
-
-bool passwordCompliesPolicy(const char* pPassword)
-{
- std::optional<OUString> oPasswordPolicy
- = officecfg::Office::Common::Security::Scripting::PasswordPolicy::get();
- if (oPasswordPolicy)
- {
- icu::ErrorCode aStatus;
- icu::UnicodeString sPassword(pPassword);
- icu::UnicodeString sRegex(oPasswordPolicy->getStr());
- icu::RegexMatcher aRegexMatcher(sRegex, sPassword, 0, aStatus);
-
- if (aRegexMatcher.matches(aStatus))
- return true;
-
- if (aStatus.isFailure())
- {
- SAL_INFO("cui.util", "Password policy regular expression failed with error: "
- << aStatus.errorName());
- }
- return false;
- }
- return true;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */