Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Lucas SCHMIDT
sight
Commits
fac8393f
Verified
Commit
fac8393f
authored
Sep 03, 2021
by
Didier WECKMANN
Browse files
refactor(ui): remove semi-deprecated password in preference
parent
c5b7d575
Changes
9
Hide whitespace changes
Inline
Side-by-side
libs/ui/base/CMakeLists.txt
View file @
fac8393f
sight_add_target
(
ui_base TYPE LIBRARY PCH pchService
)
target_link_libraries
(
ui_base PUBLIC core data service
io_session
)
target_link_libraries
(
ui_base PUBLIC core data service
)
if
(
SIGHT_BUILD_TESTS
)
add_subdirectory
(
test
)
...
...
libs/ui/base/preferences/helper.cpp
View file @
fac8393f
...
...
@@ -29,8 +29,6 @@
#include <data/Composite.hpp>
#include <data/String.hpp>
#include <io/session/PasswordKeeper.hpp>
#include <service/macros.hpp>
#include <service/registry/ObjectService.hpp>
...
...
@@ -40,75 +38,7 @@
namespace
sight
::
ui
::
base
::
preferences
{
const
std
::
string
s_PREFERENCES_KEY
=
"preferences"
;
static
const
std
::
string
s_PASSWORD_HASH_KEY
=
"~~Private~~"
;
//------------------------------------------------------------------------------
void
setPassword
(
const
core
::
crypto
::
secure_string
&
password
)
{
if
(
password
.
empty
())
{
// Remove the password
io
::
session
::
PasswordKeeper
::
setGlobalPassword
(
""
);
// Remove the password hash
data
::
Composite
::
sptr
prefs
=
getPreferences
();
if
(
prefs
&&
prefs
->
find
(
s_PASSWORD_HASH_KEY
)
!=
prefs
->
end
())
{
setPreference
(
s_PASSWORD_HASH_KEY
,
""
);
savePreferences
();
}
}
else
{
// Save the global password
io
::
session
::
PasswordKeeper
::
setGlobalPassword
(
password
);
// Save the password hash to preferences
setPreference
(
s_PASSWORD_HASH_KEY
,
std
::
string
(
io
::
session
::
PasswordKeeper
::
getGlobalPasswordHash
()));
savePreferences
();
}
}
//----------------------------------------------------------------------------
const
core
::
crypto
::
secure_string
getPassword
()
{
return
io
::
session
::
PasswordKeeper
::
getGlobalPassword
();
}
//----------------------------------------------------------------------------
bool
checkPassword
(
const
core
::
crypto
::
secure_string
&
password
)
{
const
core
::
crypto
::
secure_string
passwordHash
(
getPreference
(
s_PASSWORD_HASH_KEY
));
if
(
passwordHash
.
empty
())
{
// No password hash is stored in the preferences or there is no preferences
// We must check against s_password
return
io
::
session
::
PasswordKeeper
::
checkGlobalPassword
(
password
);
}
else
if
(
core
::
crypto
::
hash
(
password
)
==
passwordHash
)
{
// Store the verified password
io
::
session
::
PasswordKeeper
::
setGlobalPassword
(
password
);
return
true
;
}
else
{
return
false
;
}
}
//------------------------------------------------------------------------------
bool
hasPasswordHash
()
{
return
!
getPreference
(
s_PASSWORD_HASH_KEY
).
empty
();
}
const
std
::
string
s_PREFERENCES_KEY
=
"preferences"
;
//----------------------------------------------------------------------------
...
...
libs/ui/base/preferences/helper.hpp
View file @
fac8393f
...
...
@@ -81,16 +81,4 @@ T getValue(const std::string& var, const char delimiter = '%')
return
::
boost
::
lexical_cast
<
T
>
(
value
);
}
/// Sets the password to use in the application. If null or empty, erase it.
UI_BASE_API
void
setPassword
(
const
core
::
crypto
::
secure_string
&
password
);
/// @Returns the password used in the application.
UI_BASE_API
const
core
::
crypto
::
secure_string
getPassword
();
/// Checks if the given password match the hash stored in the preferences
UI_BASE_API
bool
checkPassword
(
const
core
::
crypto
::
secure_string
&
password
);
/// Checks if a password hash is stored in the preferences
UI_BASE_API
bool
hasPasswordHash
();
}
// namespace sight::ui::base::preferences
libs/ui/base/test/tu/PreferencesTest.cpp
View file @
fac8393f
...
...
@@ -129,37 +129,6 @@ void PreferencesTest::helperTest()
//------------------------------------------------------------------------------
void
PreferencesTest
::
passwordTest
()
{
// Reset password field in settings
ui
::
base
::
preferences
::
setPassword
(
core
::
crypto
::
secure_string
());
// Test default empty password (means no password)
CPPUNIT_ASSERT_EQUAL
(
ui
::
base
::
preferences
::
getPassword
(),
core
::
crypto
::
secure_string
());
// Test if there is no hash in preferences (means no password)
CPPUNIT_ASSERT_EQUAL
(
ui
::
base
::
preferences
::
hasPasswordHash
(),
false
);
// Test with a real password
const
core
::
crypto
::
secure_string
password
=
"You are the one for me, for me, for me, formidable"
;
ui
::
base
::
preferences
::
setPassword
(
password
);
CPPUNIT_ASSERT_EQUAL
(
password
,
ui
::
base
::
preferences
::
getPassword
());
// Save the hash
ui
::
base
::
preferences
::
savePreferences
();
// Test if there is a hash in preferences
CPPUNIT_ASSERT_EQUAL
(
ui
::
base
::
preferences
::
hasPasswordHash
(),
true
);
// Verify the good password
CPPUNIT_ASSERT_EQUAL
(
ui
::
base
::
preferences
::
checkPassword
(
password
),
true
);
// Verify that bad password doesn't work
CPPUNIT_ASSERT_EQUAL
(
ui
::
base
::
preferences
::
checkPassword
(
"ON DIT CHIFFRER, ET PAS CRYPTER. :-)"
),
false
);
}
//------------------------------------------------------------------------------
void
PreferencesTest
::
cleanup
()
{
// Cleanup
...
...
libs/ui/base/test/tu/PreferencesTest.hpp
View file @
fac8393f
...
...
@@ -41,7 +41,6 @@ class PreferencesTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST_SUITE
(
PreferencesTest
);
CPPUNIT_TEST
(
runtimeTest
);
CPPUNIT_TEST
(
helperTest
);
CPPUNIT_TEST
(
passwordTest
);
CPPUNIT_TEST
(
cleanup
);
CPPUNIT_TEST_SUITE_END
();
...
...
@@ -53,7 +52,6 @@ public:
void
runtimeTest
();
void
helperTest
();
void
passwordTest
();
void
cleanup
();
private:
...
...
modules/io/atoms/SReader.cpp
View file @
fac8393f
...
...
@@ -245,15 +245,6 @@ void SReader::updating()
archiveRootName
=
"root.json"
;
format
=
sight
::
io
::
atoms
::
JSON
;
}
else
if
(
extension
==
".cpz"
)
{
readArchive
=
sight
::
io
::
zip
::
ReadZipArchive
::
New
(
filePath
.
string
(),
sight
::
ui
::
base
::
preferences
::
getPassword
()
);
archiveRootName
=
"root.json"
;
format
=
sight
::
io
::
atoms
::
JSON
;
}
else
if
(
extension
==
".xml"
)
{
readArchive
=
sight
::
io
::
zip
::
ReadDirArchive
::
New
(
folderPath
.
string
());
...
...
modules/io/atoms/SWriter.cpp
View file @
fac8393f
...
...
@@ -487,26 +487,6 @@ void SWriter::updating()
archiveRootName
=
"root.json"
;
format
=
sight
::
io
::
atoms
::
JSON
;
}
else
if
(
extension
==
".cpz"
)
{
writeArchive
=
sight
::
io
::
zip
::
WriteZipArchive
::
New
(
tmpFilePath
.
string
(),
""
,
sight
::
ui
::
base
::
preferences
::
getPassword
()
);
archiveRootName
=
"root.json"
;
format
=
sight
::
io
::
atoms
::
JSON
;
}
else
if
(
extension
==
".sight"
)
{
writeArchive
=
sight
::
io
::
zip
::
WriteZipArchive
::
New
(
tmpFilePath
.
string
(),
""
,
sight
::
ui
::
base
::
preferences
::
getPassword
()
);
archiveRootName
=
"root.json"
;
format
=
sight
::
io
::
atoms
::
JSON
;
}
else
if
(
extension
==
".xml"
)
{
writeArchive
=
sight
::
io
::
zip
::
WriteDirArchive
::
New
(
tmpFolderPath
.
string
());
...
...
modules/io/pcl/CMakeLists.txt
View file @
fac8393f
...
...
@@ -4,9 +4,10 @@ find_package(PCL QUIET REQUIRED COMPONENTS common io)
target_include_directories
(
module_io_pcl SYSTEM PRIVATE
${
VTK_INCLUDE_DIRS
}
)
target_link_libraries
(
module_io_pcl PRIVATE
${
PCL_COMMON_LIBRARIES
}
${
PCL_IO_LIBRARIES
}
)
target_link_libraries
(
module_io_pcl PUBLIC
target_link_libraries
(
module_io_pcl PUBLIC
core
data
service
io_base
ui_base
)
modules/io/realsense/CMakeLists.txt
View file @
fac8393f
...
...
@@ -11,9 +11,10 @@ find_package(realsense2 QUIET REQUIRED)
target_include_directories
(
module_io_realsense SYSTEM PRIVATE
${
REALSENSE2_INCLUDE_DIRS
}
)
target_link_libraries
(
module_io_realsense PRIVATE
${
realsense2_LIBRARY
}
)
target_link_libraries
(
module_io_realsense PUBLIC
target_link_libraries
(
module_io_realsense PUBLIC
core
data
io_base
ui_base
service
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment