Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/uui/source/masterpasscrtdlg.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#include <officecfg/Office/Common.hxx>
21
#include <unotools/resmgr.hxx>
22
#include <vcl/svapp.hxx>
23
#include <vcl/vclenum.hxx>
24
#include <vcl/weld/Builder.hxx>
25
#include <vcl/weld/Dialog.hxx>
26
#include <vcl/weld/MessageDialog.hxx>
27
#include <strings.hrc>
28
#include <svl/PasswordHelper.hxx>
29
#include "masterpasscrtdlg.hxx"
30
31
// MasterPasswordCreateDialog---------------------------------------------------
32
33
IMPL_LINK_NOARG(MasterPasswordCreateDialog, EditHdl_Impl, weld::TextWidget&, void)
34
0
{
35
0
    OUString aPasswordText = m_xEDMasterPasswordCrt->get_text();
36
0
    m_xOKBtn->set_sensitive(aPasswordText.getLength() >= 1);
37
0
    m_xPasswdStrengthBar->set_percentage(
38
0
        SvPasswordHelper::GetPasswordStrengthPercentage(aPasswordText));
39
40
0
    if(m_oPasswordPolicy)
41
0
    {
42
0
        bool bPasswordMeetsPolicy
43
0
            = SvPasswordHelper::PasswordMeetsPolicy(aPasswordText, m_oPasswordPolicy);
44
0
        m_xEDMasterPasswordCrt->set_message_type(bPasswordMeetsPolicy ? weld::EntryMessageType::Normal
45
0
                                                 : weld::EntryMessageType::Error);
46
0
        m_xPasswordPolicyLabel->set_visible(!bPasswordMeetsPolicy);
47
0
    }
48
0
}
49
50
IMPL_LINK_NOARG(MasterPasswordCreateDialog, OKHdl_Impl, weld::Button&, void)
51
0
{
52
0
    if (m_oPasswordPolicy
53
0
        && !SvPasswordHelper::PasswordMeetsPolicy(m_xEDMasterPasswordCrt->get_text(),
54
0
                                                  m_oPasswordPolicy))
55
0
    {
56
0
        m_xEDMasterPasswordCrt->grab_focus();
57
0
        return;
58
0
    }
59
60
    // compare both passwords and show message box if there are not equal!!
61
0
    if (m_xEDMasterPasswordCrt->get_text() == m_xEDMasterPasswordRepeat->get_text())
62
0
        m_xDialog->response(RET_OK);
63
0
    else
64
0
    {
65
0
        OUString aErrorMsg(Translate::get(STR_ERROR_PASSWORDS_NOT_IDENTICAL, rResLocale));
66
0
        std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(m_xDialog.get(),
67
0
                                                  VclMessageType::Warning, VclButtonsType::Ok,
68
0
                                                  aErrorMsg));
69
0
        xErrorBox->run();
70
0
        m_xEDMasterPasswordCrt->set_text( OUString() );
71
0
        m_xEDMasterPasswordRepeat->set_text( OUString() );
72
0
        m_xEDMasterPasswordCrt->grab_focus();
73
0
    }
74
0
}
75
76
MasterPasswordCreateDialog::MasterPasswordCreateDialog(weld::Window* pParent, const std::locale& rLocale)
77
0
    : GenericDialogController(pParent, u"uui/ui/setmasterpassworddlg.ui"_ustr, u"SetMasterPasswordDialog"_ustr)
78
0
    , rResLocale(rLocale)
79
0
    , m_xEDMasterPasswordCrt(m_xBuilder->weld_entry(u"password1"_ustr))
80
0
    , m_xPasswordPolicyLabel(m_xBuilder->weld_label(u"passpolicylabel"_ustr))
81
0
    , m_xEDMasterPasswordRepeat(m_xBuilder->weld_entry(u"password2"_ustr))
82
0
    , m_xOKBtn(m_xBuilder->weld_button(u"ok"_ustr))
83
0
    , m_xPasswdStrengthBar(m_xBuilder->weld_level_bar(u"password1levelbar"_ustr))
84
0
    , m_oPasswordPolicy(officecfg::Office::Common::Security::Scripting::PasswordPolicy::get())
85
0
{
86
0
    m_xOKBtn->set_sensitive(false);
87
0
    m_xOKBtn->connect_clicked( LINK( this, MasterPasswordCreateDialog, OKHdl_Impl ) );
88
0
    m_xEDMasterPasswordCrt->connect_changed( LINK( this, MasterPasswordCreateDialog, EditHdl_Impl ) );
89
0
    if (m_oPasswordPolicy)
90
0
    {
91
0
        m_xPasswordPolicyLabel->set_label(
92
0
            officecfg::Office::Common::Security::Scripting::PasswordPolicyErrorMessage::get());
93
0
    }
94
0
}
95
96
MasterPasswordCreateDialog::~MasterPasswordCreateDialog()
97
0
{
98
0
}
99
100
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */