CuteHMI - Lock Screen (CuteHMI.LockScreen.2)
Gatekeeper.hpp
1#ifndef H_EXTENSIONS_CUTEHMI_LOCKSCREEN_2_INCLUDE_CUTEHMI_LOCKSCREEN_GATEKEEPER_HPP
2#define H_EXTENSIONS_CUTEHMI_LOCKSCREEN_2_INCLUDE_CUTEHMI_LOCKSCREEN_GATEKEEPER_HPP
3
4#include "internal/common.hpp"
5
6#include <cutehmi/Singleton.hpp>
7
8#include <QQmlEngine>
9
10namespace cutehmi {
11namespace lockscreen {
12
13class CUTEHMI_LOCKSCREEN_API Gatekeeper:
14 public QObject
15{
16 Q_OBJECT
17 QML_NAMED_ELEMENT(Gatekeeper)
18
19 friend class test_Gatekeeper;
20
21 public:
22 static constexpr int INITIAL_HASHES_MIN = 9000;
23 static constexpr int INITIAL_HASHES_MAX = 10000;
24
25 Q_PROPERTY(int hashesLow READ hashesLow WRITE setHashesLow NOTIFY hashesLowChanged)
26
27 Q_PROPERTY(int hashesHigh READ hashesHigh WRITE setHashesHigh NOTIFY hashesHighChanged)
28
29 Q_PROPERTY(QString password READ password WRITE setPassword NOTIFY passwordChanged)
30
31 Q_PROPERTY(QByteArray secret READ secret WRITE setSecret NOTIFY secretChanged)
32
33 explicit Gatekeeper(QObject * parent = nullptr);
34
35 int hashesLow() const;
36
37 void setHashesLow(int low);
38
39 int hashesHigh() const;
40
41 void setHashesHigh(int high);
42
43 QString password() const;
44
45 void setPassword(const QString & password);
46
47 QByteArray secret() const;
48
49 void setSecret(const QByteArray & secret);
50
51 Q_INVOKABLE virtual bool authenticate() const;
52
53 Q_INVOKABLE virtual QByteArray makeSecret(const QString & password);
54
55 signals:
56 void hashesLowChanged();
57
58 void hashesHighChanged();
59
60 void passwordChanged();
61
62 void secretChanged();
63
64 protected:
65 static QByteArray Hash(const QString & string);
66
67 int pickNumberOfHashes() const;
68
69 private:
70 struct Members {
71 int hashesMin;
72 int hashesMax;
73 QString password;
74 QByteArray secret;
75 };
77};
78
79}
80}
81
82#endif
83
84//(c)WZMP: Copyright © 2018, Wojciech Zygmuntowicz, Michal Policht. All rights reserved.
85//(c)WZMP: 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/.
86
87//(c)C: Copyright © 2021-2022, Michał Policht <michal@policht.pl>. All rights reserved.
88//(c)C: SPDX-License-Identifier: LGPL-3.0-or-later OR MIT
89//(c)C: This file is a part of CuteHMI.
90//(c)C: CuteHMI is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
91//(c)C: CuteHMI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
92//(c)C: You should have received a copy of the GNU Lesser General Public License along with CuteHMI. If not, see <https://www.gnu.org/licenses/>.
93//(c)C: Additionally, this file is licensed under terms of MIT license as expressed below.
94//(c)C: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
95//(c)C: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
96//(c)C: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Definition: Gatekeeper.hpp:15