summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSarper Akdemir <sarper.akdemir.extern@allotropia.de>2023-11-13 17:19:01 +0300
committerSarper Akdemir <sarper.akdemir.extern@allotropia.de>2023-11-15 22:02:16 +0100
commitfed7b3068dcea2ebf65314c4f212350720631706 (patch)
treeabe5cd6a918324c2bea98bc961f0171312a82541
parent32d0efa9d934ec45f2863a285d250dfc0ab137e8 (diff)
tdf#157518: enforce password policy on setmasterpassworddlg
Change-Id: I7e7adde8f0d55808d16dc9247954a7645a1d3601 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159384 Tested-by: Jenkins Reviewed-by: Sarper Akdemir <sarper.akdemir.extern@allotropia.de>
-rw-r--r--uui/source/masterpasscrtdlg.cxx25
-rw-r--r--uui/source/masterpasscrtdlg.hxx2
-rw-r--r--uui/uiconfig/ui/setmasterpassworddlg.ui44
3 files changed, 64 insertions, 7 deletions
diff --git a/uui/source/masterpasscrtdlg.cxx b/uui/source/masterpasscrtdlg.cxx
index 2216ea5a1d48..f0c456365646 100644
--- a/uui/source/masterpasscrtdlg.cxx
+++ b/uui/source/masterpasscrtdlg.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <officecfg/Office/Common.hxx>
#include <unotools/resmgr.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
@@ -33,10 +34,27 @@ IMPL_LINK_NOARG(MasterPasswordCreateDialog, EditHdl_Impl, weld::Entry&, void)
m_xOKBtn->set_sensitive(aPasswordText.getLength() >= 1);
m_xPasswdStrengthBar->set_percentage(
SvPasswordHelper::GetPasswordStrengthPercentage(aPasswordText));
+
+ if(m_oPasswordPolicy)
+ {
+ bool bPasswordMeetsPolicy
+ = SvPasswordHelper::PasswordMeetsPolicy(aPasswordText, m_oPasswordPolicy);
+ m_xEDMasterPasswordCrt->set_message_type(bPasswordMeetsPolicy ? weld::EntryMessageType::Normal
+ : weld::EntryMessageType::Error);
+ m_xPasswordPolicyLabel->set_visible(!bPasswordMeetsPolicy);
+ }
}
IMPL_LINK_NOARG(MasterPasswordCreateDialog, OKHdl_Impl, weld::Button&, void)
{
+ if (m_oPasswordPolicy
+ && !SvPasswordHelper::PasswordMeetsPolicy(m_xEDMasterPasswordCrt->get_text(),
+ m_oPasswordPolicy))
+ {
+ m_xEDMasterPasswordCrt->grab_focus();
+ return;
+ }
+
// compare both passwords and show message box if there are not equal!!
if (m_xEDMasterPasswordCrt->get_text() == m_xEDMasterPasswordRepeat->get_text())
m_xDialog->response(RET_OK);
@@ -57,13 +75,20 @@ MasterPasswordCreateDialog::MasterPasswordCreateDialog(weld::Window* pParent, co
: GenericDialogController(pParent, "uui/ui/setmasterpassworddlg.ui", "SetMasterPasswordDialog")
, rResLocale(rLocale)
, m_xEDMasterPasswordCrt(m_xBuilder->weld_entry("password1"))
+ , m_xPasswordPolicyLabel(m_xBuilder->weld_label("passpolicylabel"))
, m_xEDMasterPasswordRepeat(m_xBuilder->weld_entry("password2"))
, m_xOKBtn(m_xBuilder->weld_button("ok"))
, m_xPasswdStrengthBar(m_xBuilder->weld_level_bar("password1levelbar"))
+ , m_oPasswordPolicy(officecfg::Office::Common::Security::Scripting::PasswordPolicy::get())
{
m_xOKBtn->set_sensitive(false);
m_xOKBtn->connect_clicked( LINK( this, MasterPasswordCreateDialog, OKHdl_Impl ) );
m_xEDMasterPasswordCrt->connect_changed( LINK( this, MasterPasswordCreateDialog, EditHdl_Impl ) );
+ if (m_oPasswordPolicy)
+ {
+ m_xPasswordPolicyLabel->set_label(
+ officecfg::Office::Common::Security::Scripting::PasswordPolicyErrorMessage::get());
+ }
}
MasterPasswordCreateDialog::~MasterPasswordCreateDialog()
diff --git a/uui/source/masterpasscrtdlg.hxx b/uui/source/masterpasscrtdlg.hxx
index f7f01cda79cc..83f981190bb1 100644
--- a/uui/source/masterpasscrtdlg.hxx
+++ b/uui/source/masterpasscrtdlg.hxx
@@ -27,9 +27,11 @@ private:
const std::locale& rResLocale;
std::unique_ptr<weld::Entry> m_xEDMasterPasswordCrt;
+ std::unique_ptr<weld::Label> m_xPasswordPolicyLabel;
std::unique_ptr<weld::Entry> m_xEDMasterPasswordRepeat;
std::unique_ptr<weld::Button> m_xOKBtn;
std::unique_ptr<weld::LevelBar> m_xPasswdStrengthBar;
+ std::optional<OUString> m_oPasswordPolicy;
DECL_LINK(OKHdl_Impl, weld::Button&, void);
DECL_LINK(EditHdl_Impl, weld::Entry&, void);
diff --git a/uui/uiconfig/ui/setmasterpassworddlg.ui b/uui/uiconfig/ui/setmasterpassworddlg.ui
index 52cec48eb30a..1fd06e0e5c57 100644
--- a/uui/uiconfig/ui/setmasterpassworddlg.ui
+++ b/uui/uiconfig/ui/setmasterpassworddlg.ui
@@ -95,14 +95,43 @@
</packing>
</child>
<child>
- <object class="GtkLabel" id="label2">
+ <!-- n-columns=2 n-rows=1 -->
+ <object class="GtkGrid">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="margin_top">6</property>
- <property name="label" translatable="yes" context="setmasterpassworddlg|label2">_Enter password:</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">password1</property>
- <property name="xalign">0</property>
+ <property name="can-focus">False</property>
+ <property name="column-spacing">12</property>
+ <property name="baseline-row">1</property>
+ <child>
+ <object class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="valign">end</property>
+ <property name="margin-top">6</property>
+ <property name="vexpand">True</property>
+ <property name="label" translatable="yes" context="setmasterpassworddlg|label2">_Enter password:</property>
+ <property name="use-underline">True</property>
+ <property name="mnemonic-widget">password1</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="left-attach">0</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="passpolicylabel">
+ <property name="can-focus">False</property>
+ <property name="no-show-all">True</property>
+ <property name="halign">end</property>
+ <property name="margin-top">6</property>
+ <property name="hexpand">True</property>
+ <property name="wrap">True</property>
+ </object>
+ <packing>
+ <property name="left-attach">1</property>
+ <property name="top-attach">0</property>
+ </packing>
+ </child>
</object>
<packing>
<property name="expand">False</property>
@@ -133,6 +162,7 @@
<object class="GtkLevelBar" id="password1levelbar">
<property name="visible">True</property>
<property name="can-focus">False</property>
+ <property name="tooltip-text" translatable="yes" context="setmasterpassworddlg|password1levelbar">Bar that displays password strength visually.</property>
</object>
<packing>
<property name="expand">False</property>