include/sfx2/passwd.hxx | 3 ++ sfx2/source/dialog/passwd.cxx | 45 ++++++++++++++++++++++++++++++++ sfx2/uiconfig/ui/password.ui | 56 ++++++++++++++++++++++++++++++++--------- solenv/sanitizers/ui/sfx.suppr | 4 ++ 4 files changed, 96 insertions(+), 12 deletions(-)
New commits: commit ed72c6fbfa02cf98cb0d0f761ef5a7b9ffb894bc Author: Sarper Akdemir <sarper.akdemir.ext...@allotropia.de> AuthorDate: Wed Nov 15 14:54:42 2023 +0300 Commit: Sarper Akdemir <sarper.akdemir.ext...@allotropia.de> CommitDate: Wed Nov 15 23:05:49 2023 +0100 tdf#157518: enforce password policy on sfx2/ui/password.ui Change-Id: I115b5b05ed82f2f900bcd70ec4f52c7f749544e7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159443 Tested-by: Jenkins Reviewed-by: Sarper Akdemir <sarper.akdemir.ext...@allotropia.de> diff --git a/include/sfx2/passwd.hxx b/include/sfx2/passwd.hxx index bc5e478bbf03..3ddffed196d0 100644 --- a/include/sfx2/passwd.hxx +++ b/include/sfx2/passwd.hxx @@ -51,6 +51,7 @@ private: std::unique_ptr<weld::Label> m_xPassword1FT; std::unique_ptr<weld::Entry> m_xPassword1ED; std::unique_ptr<weld::LevelBar> m_xPassword1StrengthBar; + std::unique_ptr<weld::Label> m_xPassword1PolicyLabel; std::unique_ptr<weld::Label> m_xConfirm1FT; std::unique_ptr<weld::Entry> m_xConfirm1ED; @@ -58,6 +59,7 @@ private: std::unique_ptr<weld::Label> m_xPassword2FT; std::unique_ptr<weld::Entry> m_xPassword2ED; std::unique_ptr<weld::LevelBar> m_xPassword2StrengthBar; + std::unique_ptr<weld::Label> m_xPassword2PolicyLabel; std::unique_ptr<weld::Label> m_xConfirm2FT; std::unique_ptr<weld::Entry> m_xConfirm2ED; @@ -74,6 +76,7 @@ private: OUString maMainPwdStr; sal_uInt16 mnMinLen; SfxShowExtras mnExtras; + std::optional<OUString> moPasswordPolicy; bool mbAsciiOnly; DECL_DLLPRIVATE_LINK(OKHdl, weld::Button&, void); diff --git a/sfx2/source/dialog/passwd.cxx b/sfx2/source/dialog/passwd.cxx index a69d0aef352a..b78546722cb9 100644 --- a/sfx2/source/dialog/passwd.cxx +++ b/sfx2/source/dialog/passwd.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <officecfg/Office/Common.hxx> #include <sfx2/passwd.hxx> #include <sfx2/sfxresid.hxx> #include <sfx2/strings.hrc> @@ -38,15 +39,35 @@ void SfxPasswordDialog::ModifyHdl() bEnable = (bEnable && (m_xPassword2ED->get_text().getLength() >= mnMinLen)); m_xOKBtn->set_sensitive(bEnable); + // if there's a confirm entry, the dialog is being used for setting a password if (m_xConfirm1ED->get_visible()) { m_xPassword1StrengthBar->set_percentage( SvPasswordHelper::GetPasswordStrengthPercentage(aPassword1Text)); + bool bPasswordMeetsPolicy = SvPasswordHelper::PasswordMeetsPolicy( + aPassword1Text, moPasswordPolicy); + m_xPassword1ED->set_message_type(bPasswordMeetsPolicy ? weld::EntryMessageType::Normal + : weld::EntryMessageType::Error); + m_xPassword1PolicyLabel->set_visible(!bPasswordMeetsPolicy); } + + // if there's a confirm entry, the dialog is being used for setting a password if (m_xConfirm2ED->get_visible()) { + OUString aPassword2Text = m_xPassword2ED->get_text(); + m_xPassword2StrengthBar->set_percentage( SvPasswordHelper::GetPasswordStrengthPercentage(m_xPassword2ED->get_text())); + + // second password is optional, ignore policy if it is empty + bool bPasswordMeetsPolicy + = aPassword2Text.isEmpty() + ? true + : SvPasswordHelper::PasswordMeetsPolicy( + aPassword2Text, moPasswordPolicy); + m_xPassword2ED->set_message_type(bPasswordMeetsPolicy ? weld::EntryMessageType::Normal + : weld::EntryMessageType::Error); + m_xPassword2PolicyLabel->set_visible(!bPasswordMeetsPolicy); } } @@ -81,6 +102,19 @@ IMPL_LINK(SfxPasswordDialog, InsertTextHdl, OUString&, rTest, bool) IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl, weld::Button&, void) { + if (m_xConfirm1ED->get_visible() + && !SvPasswordHelper::PasswordMeetsPolicy(GetPassword(), moPasswordPolicy)) + { + m_xPassword1ED->grab_focus(); + return; + } + if (m_xConfirm2ED->get_visible() && !GetPassword2().isEmpty() + && !SvPasswordHelper::PasswordMeetsPolicy(GetPassword2(), moPasswordPolicy)) + { + m_xPassword2ED->grab_focus(); + return; + } + bool bConfirmFailed = bool( mnExtras & SfxShowExtras::CONFIRM ) && ( GetConfirm() != GetPassword() ); if( ( mnExtras & SfxShowExtras::CONFIRM2 ) && ( m_xConfirm2ED->get_text() != GetPassword2() ) ) @@ -114,12 +148,14 @@ SfxPasswordDialog::SfxPasswordDialog(weld::Widget* pParent, const OUString* pGro , m_xPassword1FT(m_xBuilder->weld_label("pass1ft")) , m_xPassword1ED(m_xBuilder->weld_entry("pass1ed")) , m_xPassword1StrengthBar(m_xBuilder->weld_level_bar("pass1bar")) + , m_xPassword1PolicyLabel(m_xBuilder->weld_label("pass1policylabel")) , m_xConfirm1FT(m_xBuilder->weld_label("confirm1ft")) , m_xConfirm1ED(m_xBuilder->weld_entry("confirm1ed")) , m_xPassword2Box(m_xBuilder->weld_frame("password2frame")) , m_xPassword2FT(m_xBuilder->weld_label("pass2ft")) , m_xPassword2ED(m_xBuilder->weld_entry("pass2ed")) , m_xPassword2StrengthBar(m_xBuilder->weld_level_bar("pass2bar")) + , m_xPassword2PolicyLabel(m_xBuilder->weld_label("pass2policylabel")) , m_xConfirm2FT(m_xBuilder->weld_label("confirm2ft")) , m_xConfirm2ED(m_xBuilder->weld_entry("confirm2ed")) , m_xMinLengthFT(m_xBuilder->weld_label("minlenft")) @@ -130,6 +166,7 @@ SfxPasswordDialog::SfxPasswordDialog(weld::Widget* pParent, const OUString* pGro , maEmptyPwdStr(SfxResId(STR_PASSWD_EMPTY)) , mnMinLen(5) , mnExtras(SfxShowExtras::NONE) + , moPasswordPolicy(officecfg::Office::Common:: Security::Scripting::PasswordPolicy::get()) , mbAsciiOnly(false) { Link<weld::Entry&,void> aLink = LINK(this, SfxPasswordDialog, EditModifyHdl); @@ -142,6 +179,14 @@ SfxPasswordDialog::SfxPasswordDialog(weld::Widget* pParent, const OUString* pGro m_xConfirm2ED->connect_insert_text(aLink2); m_xOKBtn->connect_clicked(LINK(this, SfxPasswordDialog, OKHdl)); + if(moPasswordPolicy) + { + m_xPassword1PolicyLabel->set_label( + officecfg::Office::Common::Security::Scripting::PasswordPolicyErrorMessage::get()); + m_xPassword2PolicyLabel->set_label( + officecfg::Office::Common::Security::Scripting::PasswordPolicyErrorMessage::get()); + } + if (pGroupText) m_xPassword1Box->set_label(*pGroupText); diff --git a/sfx2/uiconfig/ui/password.ui b/sfx2/uiconfig/ui/password.ui index 0eabdd68682b..f376fdcc7c0b 100644 --- a/sfx2/uiconfig/ui/password.ui +++ b/sfx2/uiconfig/ui/password.ui @@ -87,7 +87,7 @@ <property name="label-xalign">0</property> <property name="shadow-type">none</property> <child> - <!-- n-columns=2 n-rows=4 --> + <!-- n-columns=2 n-rows=5 --> <object class="GtkGrid" id="grid1"> <property name="visible">True</property> <property name="can-focus">False</property> @@ -120,7 +120,7 @@ </object> <packing> <property name="left-attach">0</property> - <property name="top-attach">1</property> + <property name="top-attach">2</property> </packing> </child> <child> @@ -134,7 +134,7 @@ </object> <packing> <property name="left-attach">0</property> - <property name="top-attach">3</property> + <property name="top-attach">4</property> </packing> </child> <child> @@ -168,7 +168,7 @@ </object> <packing> <property name="left-attach">1</property> - <property name="top-attach">1</property> + <property name="top-attach">2</property> </packing> </child> <child> @@ -188,7 +188,7 @@ </object> <packing> <property name="left-attach">1</property> - <property name="top-attach">3</property> + <property name="top-attach">4</property> </packing> </child> <child> @@ -198,12 +198,28 @@ </object> <packing> <property name="left-attach">1</property> - <property name="top-attach">2</property> + <property name="top-attach">3</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="pass1policylabel"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="halign">end</property> + <property name="hexpand">False</property> + <property name="wrap">True</property> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">1</property> </packing> </child> <child> <placeholder/> </child> + <child> + <placeholder/> + </child> </object> </child> <child type="label"> @@ -230,7 +246,7 @@ <property name="label-xalign">0</property> <property name="shadow-type">none</property> <child> - <!-- n-columns=2 n-rows=3 --> + <!-- n-columns=2 n-rows=4 --> <object class="GtkGrid" id="grid2"> <property name="visible">True</property> <property name="can-focus">False</property> @@ -249,7 +265,7 @@ </object> <packing> <property name="left-attach">0</property> - <property name="top-attach">0</property> + <property name="top-attach">1</property> </packing> </child> <child> @@ -263,7 +279,7 @@ </object> <packing> <property name="left-attach">0</property> - <property name="top-attach">2</property> + <property name="top-attach">3</property> </packing> </child> <child> @@ -283,7 +299,7 @@ </object> <packing> <property name="left-attach">1</property> - <property name="top-attach">0</property> + <property name="top-attach">1</property> </packing> </child> <child> @@ -303,7 +319,7 @@ </object> <packing> <property name="left-attach">1</property> - <property name="top-attach">2</property> + <property name="top-attach">3</property> </packing> </child> <child> @@ -313,9 +329,25 @@ </object> <packing> <property name="left-attach">1</property> - <property name="top-attach">1</property> + <property name="top-attach">2</property> </packing> </child> + <child> + <object class="GtkLabel" id="pass2policylabel"> + <property name="can-focus">False</property> + <property name="no-show-all">True</property> + <property name="halign">end</property> + <property name="hexpand">False</property> + <property name="wrap">True</property> + </object> + <packing> + <property name="left-attach">1</property> + <property name="top-attach">0</property> + </packing> + </child> + <child> + <placeholder/> + </child> <child> <placeholder/> </child> diff --git a/solenv/sanitizers/ui/sfx.suppr b/solenv/sanitizers/ui/sfx.suppr index fdcd03fb41c2..58fcd42eb62d 100644 --- a/solenv/sanitizers/ui/sfx.suppr +++ b/solenv/sanitizers/ui/sfx.suppr @@ -51,3 +51,7 @@ sfx2/uiconfig/ui/versioncommentdialog.ui://GtkTextView[@id='textview'] no-labell sfx2/uiconfig/ui/linefragment.ui://GtkEntry[@id='duration'] no-labelled-by sfx2/uiconfig/ui/linefragment.ui://GtkEntry[@id='valueedit'] no-labelled-by sfx2/uiconfig/ui/linefragment.ui://GtkSpinButton[@id='time'] no-labelled-by +sfx2/uiconfig/ui/password.ui://GtkLevelBar[@id='pass1bar'] no-labelled-by +sfx2/uiconfig/ui/password.ui://GtkLabel[@id='pass1policylabel'] orphan-label +sfx2/uiconfig/ui/password.ui://GtkLevelBar[@id='pass2bar'] no-labelled-by +sfx2/uiconfig/ui/password.ui://GtkLabel[@id='pass2policylabel'] orphan-label