From 831d7b854beaff2d95ff81265a15c6030c89a519 Mon Sep 17 00:00:00 2001 From: Saagar Arya Date: Thu, 14 Nov 2024 11:31:02 -0500 Subject: [PATCH 01/14] [Config] Add password algorithm selector --- SQL/0000-00-03-ConfigTables.sql | 12 +++++++----- .../2024-11-14-Add-Password-Algo-Config.sql | 7 +++++++ htdocs/postdeploy.php | 4 +++- modules/configuration/php/configuration.class.inc | 8 ++++++++ .../configuration/templates/form_configuration.tpl | 10 +++++++++- php/installer/Installer.class.inc | 4 +++- php/libraries/Password.class.inc | 4 +++- php/libraries/SinglePointLogin.class.inc | 6 ++++-- tools/resetpassword.php | 4 +++- 9 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 SQL/New_patches/2024-11-14-Add-Password-Algo-Config.sql diff --git a/SQL/0000-00-03-ConfigTables.sql b/SQL/0000-00-03-ConfigTables.sql index e7b4d637a0d..0d32b1d3425 100644 --- a/SQL/0000-00-03-ConfigTables.sql +++ b/SQL/0000-00-03-ConfigTables.sql @@ -8,7 +8,7 @@ CREATE TABLE `ConfigSettings` ( `Description` varchar(255) DEFAULT NULL, `Visible` tinyint(1) DEFAULT '0', `AllowMultiple` tinyint(1) DEFAULT '0', - `DataType` ENUM('text','boolean','email','instrument','textarea','scan_type','date_format','lookup_center','path','web_path', 'log_level') DEFAULT NULL, + `DataType` ENUM('text','boolean','email','instrument','textarea','scan_type','date_format','lookup_center','path','web_path','log_level','password_algo') DEFAULT NULL, `Parent` int(11) DEFAULT NULL, `Label` varchar(255) DEFAULT NULL, `OrderNumber` int(11) DEFAULT NULL, @@ -59,10 +59,11 @@ INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'citation_policy', 'Citation Policy for Acknowledgements module', 1, 0, 'textarea', ID, 'Citation Policy', 25 FROM ConfigSettings WHERE Name="study"; INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'CSPAdditionalHeaders', 'Extensions to the Content-security policy allow only for self-hosted content', 1, 0, 'text', ID, 'Content-Security Extensions', 26 FROM ConfigSettings WHERE Name="study"; INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'usePwnedPasswordsAPI', 'Whether to query the Have I Been Pwned password API on password changes to prevent the usage of common and breached passwords', 1, 0, 'boolean', ID, 'Enable "Pwned Password" check', 27 FROM ConfigSettings WHERE Name="study"; -INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'dateDisplayFormat', 'The date format to use throughout LORIS for displaying date information - formats for date inputs are browser- and locale-dependent.', 1, 0, 'text', ID, 'Date display format', 28 FROM ConfigSettings WHERE Name="study"; -INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'adminContactEmail', 'An email address that users can write to in order to report issues or ask question', 1, 0, 'text', ID, 'Administrator Email', 29 FROM ConfigSettings WHERE Name="study"; -INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'UserMaximumDaysInactive', 'The maximum number of days since last login before making a user inactive', 1, 0, 'text', ID, 'Maximum Days Before Making User Inactive', 30 FROM ConfigSettings WHERE Name="study"; -INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'useDoB', 'Use DoB (Date of Birth)', 1, 0, 'boolean', ID, 'Use DoB', 31 FROM ConfigSettings WHERE Name="study"; +INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'passwordAlgorithm','Which PHP password algorithm to use for hashing the passwords',1,0,'password_algo',1,'Password Algorithm',28 FROM ConfigSettings WHERE Name="study"; +INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'dateDisplayFormat', 'The date format to use throughout LORIS for displaying date information - formats for date inputs are browser- and locale-dependent.', 1, 0, 'text', ID, 'Date display format', 29 FROM ConfigSettings WHERE Name="study"; +INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'adminContactEmail', 'An email address that users can write to in order to report issues or ask question', 1, 0, 'text', ID, 'Administrator Email', 30 FROM ConfigSettings WHERE Name="study"; +INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'UserMaximumDaysInactive', 'The maximum number of days since last login before making a user inactive', 1, 0, 'text', ID, 'Maximum Days Before Making User Inactive', 31 FROM ConfigSettings WHERE Name="study"; +INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'useDoB', 'Use DoB (Date of Birth)', 1, 0, 'boolean', ID, 'Use DoB', 32 FROM ConfigSettings WHERE Name="study"; INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, Label, OrderNumber) VALUES ('paths', 'Specify directories where LORIS-related files are stored or created. Take care when editing these fields as changing them incorrectly can cause certain modules to lose functionality.', 1, 0, 'Paths', 2); INSERT INTO ConfigSettings (Name, Description, Visible, AllowMultiple, DataType, Parent, Label, OrderNumber) SELECT 'imagePath', 'Path to images for display in Imaging Browser (e.g. /data/$project/data/) ', 1, 0, 'text', ID, 'Images', 9 FROM ConfigSettings WHERE Name="paths"; @@ -282,6 +283,7 @@ INSERT INTO Config (ConfigID, Value) SELECT ID, 't1' FROM ConfigSettings WHER INSERT INTO Config (ConfigID, Value) SELECT ID, 't2' FROM ConfigSettings WHERE Name="modalities_to_deface"; INSERT INTO Config (ConfigID, Value) SELECT ID, 'pd' FROM ConfigSettings WHERE Name="modalities_to_deface"; INSERT INTO Config (ConfigID, Value) SELECT ID, 'false' FROM ConfigSettings WHERE Name="usePwnedPasswordsAPI"; +INSERT INTO Config (ConfigID, Value) SELECT ID, 'PASSWORD_DEFAULT' FROM ConfigSettings WHERE Name="passwordAlgorithm"; INSERT INTO Config (ConfigID, Value) SELECT ID, 'Y-m-d H:i:s' FROM ConfigSettings WHERE Name="dateDisplayFormat"; INSERT INTO Config (ConfigID, Value) SELECT ID, '/data/issue_tracker/' FROM ConfigSettings WHERE Name="IssueTrackerDataPath"; INSERT INTO Config (ConfigID, Value) SELECT ID, '' FROM ConfigSettings WHERE Name="adminContactEmail"; diff --git a/SQL/New_patches/2024-11-14-Add-Password-Algo-Config.sql b/SQL/New_patches/2024-11-14-Add-Password-Algo-Config.sql new file mode 100644 index 00000000000..1eda15db7ae --- /dev/null +++ b/SQL/New_patches/2024-11-14-Add-Password-Algo-Config.sql @@ -0,0 +1,7 @@ +ALTER TABLE ConfigSettings +MODIFY COLUMN DataType enum('text','boolean','email','instrument','textarea','scan_type','date_format','lookup_center','path','web_path','log_level', 'password_algo') DEFAULT NULL; + +INSERT INTO `ConfigSettings` (`Name`, `Description`, `Visible`, `AllowMultiple`, `DataType`, `Parent`, `Label`, `OrderNumber`) +VALUES ('passwordAlgorithm','Which PHP password algorithm to use for hashing the passwords',1,0,'password_algo',1,'Password Algorithm',28); + +INSERT INTO Config (`ConfigID`, `Value`) VALUES (LAST_INSERT_ID(), 'PASSWORD_DEFAULT'); \ No newline at end of file diff --git a/htdocs/postdeploy.php b/htdocs/postdeploy.php index 86fd80d7072..8c1a7e66b15 100644 --- a/htdocs/postdeploy.php +++ b/htdocs/postdeploy.php @@ -47,7 +47,9 @@ $sqls = file_get_contents($path_to_file); $conn->exec($sqls); -$pw = password_hash($password, PASSWORD_DEFAULT); +$config =& \NDB_Config::singleton(); +$password_algo = $config->getSetting("passwordAlgorithm"); +$pw = password_hash($password, $password_algo); $conn->query( "UPDATE users SET Password_hash=" . $conn->quote($pw) . diff --git a/modules/configuration/php/configuration.class.inc b/modules/configuration/php/configuration.class.inc index 06c2266f1b4..4696b89725c 100644 --- a/modules/configuration/php/configuration.class.inc +++ b/modules/configuration/php/configuration.class.inc @@ -88,6 +88,14 @@ class Configuration extends \NDB_Form 'emergency' => 'Emergency', ]; + $this->tpl_data['password_algos'] = [ + '' => '', + 'PASSWORD_DEFAULT' => 'PASSWORD_DEFAULT', + 'PASSWORD_BCRYPT' => 'PASSWORD_BCRYPT', + 'PASSWORD_ARGON2I' => 'PASSWORD_ARGON2I', + 'PASSWORD_ARGON2ID' => 'PASSWORD_ARGON2ID' + ]; + $this->tpl_data['date_format'] = $date_format; $this->tpl_data['lookup_center'] = [ '' => '', diff --git a/modules/configuration/templates/form_configuration.tpl b/modules/configuration/templates/form_configuration.tpl index 2ed16e8a299..ebf217d4e0f 100644 --- a/modules/configuration/templates/form_configuration.tpl +++ b/modules/configuration/templates/form_configuration.tpl @@ -22,7 +22,13 @@ {/function} - +{function name=createPasswordAlgo} + +{/function} {function name=createScanType}