Verified Commit bef282a8 authored by Didier WECKMANN's avatar Didier WECKMANN
Browse files

misc: apply review suggestions

parent bdb5aec4
......@@ -89,6 +89,13 @@ public:
return core::crypto::decrypt(m_password, computePasswordKey()) == password;
}
//------------------------------------------------------------------------------
inline void resetPassword()
{
m_password.clear();
}
private:
/// Generate a pseudo random password key to store the password obfuscated
......@@ -139,6 +146,13 @@ bool PasswordKeeper::checkPassword(const core::crypto::secure_string& password)
//------------------------------------------------------------------------------
void PasswordKeeper::resetPassword()
{
return m_pimpl->resetPassword();
}
//------------------------------------------------------------------------------
core::crypto::secure_string PasswordKeeper::getGlobalPasswordHash()
{
return core::crypto::hash(PasswordKeeper::getGlobalPassword());
......@@ -170,4 +184,13 @@ bool PasswordKeeper::checkGlobalPassword(const core::crypto::secure_string& pass
return core::crypto::decrypt(s_password, computeGlobalPasswordKey()) == password;
}
//------------------------------------------------------------------------------
void PasswordKeeper::resetGlobalPassword()
{
std::lock_guard guard(s_password_mutex);
s_password.clear();
}
} // namespace sight::io::session
......@@ -82,12 +82,18 @@ public:
/// @param password the password to verify against global stored password
IO_SESSION_API static bool checkGlobalPassword(const core::crypto::secure_string& password);
/// Reset the global password
IO_SESSION_API static void resetGlobalPassword();
/// Gets the password
IO_SESSION_API core::crypto::secure_string getPasswordHash() const;
/// Gets the password
IO_SESSION_API core::crypto::secure_string getPassword() const;
/// Reset the password
IO_SESSION_API void resetPassword();
/// Sets the password
/// @param password the new password
IO_SESSION_API void setPassword(const core::crypto::secure_string& password);
......
......@@ -38,6 +38,13 @@ namespace sight::ui::qml
namespace dialog
{
static auto enumRegistered =
[]
{
qmlRegisterUncreatableType<InputDialog>("sight.InputDialog", 1, 0, "EchoMode", "Enum EchoMode is not a type");
return true;
}();
//------------------------------------------------------------------------------
InputDialog::InputDialog(ui::base::GuiBaseObject::Key)
......@@ -68,7 +75,7 @@ void InputDialog::setMessage(const std::string& msg)
void InputDialog::setEchoMode(base::dialog::IInputDialog::EchoMode echoMode)
{
m_echoMode = static_cast<decltype(m_echoMode)>(echoMode);
m_echoMode = echoMode;
}
//------------------------------------------------------------------------------
......
......@@ -54,10 +54,11 @@ class UI_QML_CLASS_API InputDialog : public QObject,
public ui::base::dialog::IInputDialog
{
Q_OBJECT
Q_ENUM(EchoMode)
Q_PROPERTY(QString input MEMBER m_input NOTIFY inputChanged)
Q_PROPERTY(QString message MEMBER m_message NOTIFY messageChanged)
Q_PROPERTY(QString title MEMBER m_title NOTIFY titleChanged)
Q_PROPERTY(std::uint8_t echoMode MEMBER m_echoMode NOTIFY echoModeChanged)
Q_PROPERTY(EchoMode echoMode MEMBER m_echoMode NOTIFY echoModeChanged)
public:
......@@ -107,7 +108,7 @@ private:
QString m_input;
/// Echo mode for the TextField
std::uint8_t m_echoMode;
EchoMode m_echoMode {EchoMode::DEFAULT};
};
} // namespace dialog
......
......@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.12
import QtQuick.Window 2.12
import sight.style 1.0
import sight.InputDialog 1.0
Window {
id: window
......@@ -39,7 +40,7 @@ Window {
id: answer
Layout.fillWidth: true
placeholderText: inputDialog.input
echoMode: inputDialog.echoMode == 1 ? TextInput.NoEcho : inputDialog.echoMode == 2 ? TextInput.Password : inputDialog.echoMode == 3 ? TextInput.PasswordEchoOnEdit : TextInput.Normal
echoMode: inputDialog.echoMode == EchoMode.NOECHO ? TextInput.NoEcho : inputDialog.echoMode == EchoMode.PASSWORD ? TextInput.Password : inputDialog.echoMode == EchoMode.ECHO_ON_EDIT ? TextInput.PasswordEchoOnEdit : TextInput.Normal
}
}
......
......@@ -208,7 +208,7 @@ void SReader::updating()
"Enter Password",
"Password:",
globalPassword.c_str(),
sight::ui::base::dialog::InputDialog::EchoMode::ECHO_ON_EDIT
sight::ui::base::dialog::InputDialog::EchoMode::PASSWORD
)
);
......@@ -292,6 +292,12 @@ void SReader::updating()
else
{
m_pimpl->m_passwordRetry = 0;
// Reset old wrong password
if(m_pimpl->m_passwordPolicy == PasswordKeeper::PasswordPolicy::ONCE)
{
PasswordKeeper::resetGlobalPassword();
}
}
}
catch(std::exception& _e)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment