Avoid potential negative array index access to cached text.
[LibreOffice.git] / include / sfx2 / passwd.hxx
blob3ddffed196d03d9366df03176d4d5aa828840185
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_SFX2_PASSWD_HXX
20 #define INCLUDED_SFX2_PASSWD_HXX
22 #include <sal/config.h>
23 #include <sfx2/dllapi.h>
24 #include <vcl/weld.hxx>
25 #include <o3tl/typed_flags_set.hxx>
27 // defines ---------------------------------------------------------------
29 enum class SfxShowExtras
31 NONE = 0x0000,
32 USER = 0x0001,
33 CONFIRM = 0x0002,
34 PASSWORD2 = 0x0004,
35 CONFIRM2 = 0x0008,
36 ALL = USER | CONFIRM
38 namespace o3tl
40 template<> struct typed_flags<SfxShowExtras> : is_typed_flags<SfxShowExtras, 0x0f> {};
43 // class SfxPasswordDialog -----------------------------------------------
45 class SFX2_DLLPUBLIC SfxPasswordDialog final : public weld::GenericDialogController
47 private:
48 std::unique_ptr<weld::Frame> m_xPassword1Box;
49 std::unique_ptr<weld::Label> m_xUserFT;
50 std::unique_ptr<weld::Entry> m_xUserED;
51 std::unique_ptr<weld::Label> m_xPassword1FT;
52 std::unique_ptr<weld::Entry> m_xPassword1ED;
53 std::unique_ptr<weld::LevelBar> m_xPassword1StrengthBar;
54 std::unique_ptr<weld::Label> m_xPassword1PolicyLabel;
55 std::unique_ptr<weld::Label> m_xConfirm1FT;
56 std::unique_ptr<weld::Entry> m_xConfirm1ED;
58 std::unique_ptr<weld::Frame> m_xPassword2Box;
59 std::unique_ptr<weld::Label> m_xPassword2FT;
60 std::unique_ptr<weld::Entry> m_xPassword2ED;
61 std::unique_ptr<weld::LevelBar> m_xPassword2StrengthBar;
62 std::unique_ptr<weld::Label> m_xPassword2PolicyLabel;
63 std::unique_ptr<weld::Label> m_xConfirm2FT;
64 std::unique_ptr<weld::Entry> m_xConfirm2ED;
66 std::unique_ptr<weld::Label> m_xMinLengthFT;
67 std::unique_ptr<weld::Label> m_xOnlyAsciiFT;
69 std::unique_ptr<weld::Button> m_xOKBtn;
71 std::shared_ptr<weld::MessageDialog> m_xConfirmFailedDialog;
73 OUString maMinLenPwdStr;
74 OUString maMinLenPwdStr1;
75 OUString maEmptyPwdStr;
76 OUString maMainPwdStr;
77 sal_uInt16 mnMinLen;
78 SfxShowExtras mnExtras;
79 std::optional<OUString> moPasswordPolicy;
81 bool mbAsciiOnly;
82 DECL_DLLPRIVATE_LINK(OKHdl, weld::Button&, void);
83 DECL_DLLPRIVATE_LINK(InsertTextHdl, OUString&, bool);
84 DECL_DLLPRIVATE_LINK(EditModifyHdl, weld::Entry&, void);
85 void ModifyHdl();
87 void SetPasswdText();
89 public:
90 SfxPasswordDialog(weld::Widget* pParent, const OUString* pGroupText = nullptr);
92 OUString GetUser() const
94 return m_xUserED->get_text();
96 OUString GetPassword() const
98 return m_xPassword1ED->get_text();
100 OUString GetConfirm() const
102 return m_xConfirm1ED->get_text();
104 OUString GetPassword2() const
106 return m_xPassword2ED->get_text();
108 void SetGroup2Text(const OUString& i_rText)
110 m_xPassword2Box->set_label(i_rText);
112 void SetMinLen(sal_uInt16 Len);
113 void SetEditHelpId(const OUString& rId)
115 m_xPassword1ED->set_help_id(rId);
117 /* tdf#60874 we need a custom help ID for the Confirm
118 field of the Protect Document window */
119 void SetConfirmHelpId(const OUString& rId)
121 m_xConfirm1ED->set_help_id(rId);
124 void ShowExtras(SfxShowExtras nExtras)
126 mnExtras = nExtras;
129 void AllowAsciiOnly();
130 void ShowMinLengthText(bool bShow);
132 void PreRun();
134 virtual short run() override;
136 ~SfxPasswordDialog();
139 #endif // INCLUDED_SFX2_PASSWD_HXX
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */