Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: ability to change custom password fields #751

Closed
wants to merge 27 commits into from
Closed

feature: ability to change custom password fields #751

wants to merge 27 commits into from

Conversation

markus-96
Copy link
Contributor

I think I have written everything needed for this feature. Only the messages shown on the page have to be changed, and also the translations. I will try my best here. I will remove [in progress] when everything is finished and after some additional testing.

You will be able to:

  • setup as many app-passwords as you want,
  • set the name of the app and the corresponding attribute,
  • setup additional password policies,
  • setup who changes the password,
  • the hash algorithm

You can use it also for updating user information, but I do not think this would be very user friendly.

Also, take care about the discussion regarding this feature: #745

@markus-96
Copy link
Contributor Author

markus-96 commented Feb 7, 2023

It would also be great to share what you think!

In config.inc.local.php, the configuration could look like this:

$change_apppwd = array(
    array(
        'attribute' => 'sambaNTpassword',
        'label' => 'Wifi Password',
        'who_change_password' => 'user',
        'hash' => 'NTLM',
        'msg_changehelpextramessage' => "you have to do this and that and this password is meant for wifi",
        'pwd_policy_config' => array(
            'pwd_show_policy' => true,
            'pwd_no_reuse' => true,
            'pwd_min_length' => 6
        )
    ),
    array(
        'attribute' => 'dishwasher',
        'label' => 'Dishwasher',
        'who_change_password' => 'manager',
        'hash' => 'MD5',
        'pwd_policy_config' => array(
            'pwd_no_reuse' => true
        )
    )
);

@coudot coudot added this to the 1.6.0 milestone Feb 8, 2023
@markus-96
Copy link
Contributor Author

i think it is ready for testing, it would be great if someone could have a short look on my code and say if my code meets the expectations of this project. Thanks in advance!

Default configuration for apppwds is the one set for the main password.
@markus-96
Copy link
Contributor Author

question: I have set the default configuration with for-loops in config.inc.php. Or should I move it to changeapppwd.php?

Is there a reason why $pwd_forbidden_chars = ""; and $pwd_show_policy_pos = "above"; is not set in conf.inc.php?

@coudot
Copy link
Member

coudot commented Feb 12, 2023

Hello @markus-96,

I have set the default configuration with for-loops in config.inc.php. Or should I move it to changeapppwd.php?

you should not put too much logic in config.inc.php, only configuration parameters.

Is there a reason why $pwd_forbidden_chars = ""; and $pwd_show_policy_pos = "above"; is not set in conf.inc.php?

This attributes are present in config.inc.php, the first is commented, but not the second

@markus-96
Copy link
Contributor Author

Hello @markus-96,

I have set the default configuration with for-loops in config.inc.php. Or should I move it to changeapppwd.php?

you should not put too much logic in config.inc.php, only configuration parameters.

Is one for loop ok for setting the defaults for each app password?

Is there a reason why $pwd_forbidden_chars = ""; and $pwd_show_policy_pos = "above"; is not set in conf.inc.php?

This attributes are present in config.inc.php, the first is commented, but not the second

Oh, seams like I have overseen this.. Then I am curious why $pwd_forbidden_chars is set on line 127 in index.php and not in config.inc.php?

And what is it about the logic in line 229, where $pwd_show_policy_pos is always set due to line 153?

@coudot
Copy link
Member

coudot commented Feb 12, 2023

Is one for loop ok for setting the defaults for each app password?

I think so.

Oh, seams like I have overseen this.. Then I am curious why $pwd_forbidden_chars is set on line 127 in index.php and not in config.inc.php?

It was a new attribute, so to avoid warnings if the attribute was not defined in previous config version, we set a default value in index.php. Maybe we should indeed initialize all parameters in config.inc.php, but this is out of scope of the current PR.

And what is it about the logic in line 229, where $pwd_show_policy_pos is always set due to line 153?

There is indeed no need for the test line 229, the code can be improved.

@markus-96 markus-96 changed the title [in progress] feature: ability to change app passwords feature: ability to change app passwords Feb 24, 2023
@markus-96 markus-96 marked this pull request as ready for review February 24, 2023 14:40
@markus-96
Copy link
Contributor Author

Do I need to add translations to every single lang file? Or is it ok to add the english translation everywhere?

@coudot
Copy link
Member

coudot commented Feb 25, 2023

Do I need to add translations to every single lang file? Or is it ok to add the english translation everywhere?

Yes, just put english everywhere

htdocs/index.php Outdated
@@ -18,6 +18,12 @@
require_once("../lib/functions.inc.php");
if ($use_captcha) {
require_once("../lib/captcha.inc.php");
} else if ($change_apppwd != false) {
for ($i = 0; $i < count($change_apppwd); $i++) {
if (isset($change_apppwd['use_captcha']) && $change_apppwd['use_captcha']) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of course it has to be
if (isset($change_apppwd[i]['use_captcha']) && $change_apppwd[i]['use_captcha']) {
will fix today...

@markus-96
Copy link
Contributor Author

Hi, I have marked this as ready for review more than one month ago. Will there be any update soon?

As a background: This was my first real contact with PHP and this is also my first PR to an open source project. I am ready for any criticism since I want to get better. I am excited about what the community thinks about this PR and may also be a bit impatient, sorry for that..

@coudot
Copy link
Member

coudot commented Apr 5, 2023

Hello @markus-96

sorry for the delay, I don't have too much time, but the PR is targeted for the next version (1.6), no release date for the moment...

@markus-96
Copy link
Contributor Author

Are the tests in the tests folder actually used? I am asking because it seems to me like they are incompatible since about 2017 with newer versions of phpunit greater than 5. I cant run tests with phpunit, version greater than 5, without changing that the test-classes do extend \PHPUnit\Framework\TestCase and not \PHPUnit_Framework_TestCase.

With phpunit version 5.7.25, I get the following:

PHP Warning:  Private methods cannot be final as they are never overridden by other classes in phar://C:/Users/user/Downloads/phpunit-5.7.25.phar/phpunit/Util/Configuration.php on line 162

Warning: Private methods cannot be final as they are never overridden by other classes in phar://C:/Users/user/Downloads/phpunit-5.7.25.phar/phpunit/Util/Configuration.php on line 162
PHP Fatal error:  Cannot use 'Mixed' as class name as it is reserved in phar://C:/Users/user/Downloads/phpunit-5.7.25.phar/phpdocumentor-type-resolver/Types/Mixed.php on line 20

Fatal error: Cannot use 'Mixed' as class name as it is reserved in phar://C:/Users/user/Downloads/phpunit-5.7.25.phar/phpdocumentor-type-resolver/Types/Mixed.php on line 20

I am running php v8.0.25 right now..

@coudot
Copy link
Member

coudot commented Aug 16, 2023

Are the tests in the tests folder actually used?

They should but CI has been disabled since travis changed its community approach.

@coudot coudot self-requested a review August 16, 2023 17:47
@coudot
Copy link
Member

coudot commented Aug 16, 2023

@markus-96 Is it ready for review or do you plan to commit other modifications?

@markus-96
Copy link
Contributor Author

@markus-96 Is it ready for review or do you plan to commit other modifications?

some functions are not compatible with php7 (type declaration) , will change that. But that is the only thing that comes to my mind right now, will wait for your review!

@markus-96
Copy link
Contributor Author

Are the tests in the tests folder actually used?

They should but CI has been disabled since travis changed its community approach.

I have tried a bit with github workflows in this branch: https://github.com/markus-96/self-service-password/tree/phpunit-workflow
maybe this comes in handy, could create a new pull request for this or leave it up to you. The branch is a bit messed up, sorry for that

@coudot
Copy link
Member

coudot commented Aug 17, 2023

will wait for your review!

Thanks, I'll try to work on it next month, the goal is to include your contribution in next release.

@coudot
Copy link
Member

coudot commented Aug 17, 2023

I have tried a bit with github workflows in this branch: https://github.com/markus-96/self-service-password/tree/phpunit-workflow maybe this comes in handy, could create a new pull request for this or leave it up to you. The branch is a bit messed up, sorry for that

Thanks, I'll have a look.

Copy link

@davidcoutadeur davidcoutadeur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, thanks for your contribution.

In my opinion, I think this feature is really not common. Anyway, it can be interesting to add it if we make it more generic. (See my comments in the code)

There is still work to do as you should refactor your code on top of "master" branch and not 1.5, and adapt to the evolution that appeared in the meantime.

Thanks for your work.

@@ -399,11 +399,56 @@
# Smarty debug mode - will popup debug information on web interface
$smarty_debug = false;

## App Passwords
# Change App Passwords
$change_apppwd = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the false type here is not compatible with parsing the array.
You should set a default value equal to empty array

$change_apppwd = [];

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is adopted, default is an empty array. The check if this feature is enabled is now if (!empty($change_apppwd))

if (!isset($change_apppwd[$i]['shadow_options']['shadow_expire_days'])) { $change_apppwd[$i]['shadow_options']['shadow_expire_days'] = -1; }
}
unset($i);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not set these configuration parameters in config.inc.php, but rather in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked here: #751 (comment)
and got the answer one for-loop is ok, but of course, I can move it. But setting the label will have to be done on every request, so this has to be in index.php then.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My answer was indeed to remove code from config, so it should be in your apppwd page code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is one for loop ok for setting the defaults for each app password?

I think so.

Misunderstood that, is moved now to apppwd.php, except for ['label'] and ['msg_changehelpextramessage'], this is moved to index.php.

Background
----------

This Feature enables you to configure individiual Application Passwords that are

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some semantics here: why is this feature tagged as "application password".

If I understand the feature correctly, the goal is just to fill a custom password field.

I think we should make this feature more generic.

For example:

   $change_apppwd = array(
      array(
        'attribute' => "customPasswordField",
        'hash' => "MD5",
        'label' => "Custom password"
      )
   )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feature should be this generic, as far as I can tell. If you are in need for a custom password field, the password is needed for some application, for example WLAN. You want to store the hash in the field "wlanPassword", with an NTLM hash. On the website, you want the menu to include a button "Change password for WLAN".
This results in:

   $change_apppwd = array(
      array(
        'attribute' => "wlanPassword",
        'hash' => "NTLM",
        'label' => "WLAN"
      )
   )

My PR does not provide an application called password. It is meant for changing passwords of certain applications.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, your PR allows to change a custom LDAP field of any object.

In your use case, you name the object an "application", but it could be any other object, including a user, an organization,...

Whether this field (which turns to be a password) is used by 0, 1, or more applications, SSP or LDAP should not be aware of. (moreover it can change with time)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The object is defined by the login name, so it is bound to a user object.

The field can be any attribute, as long as the user object may include the attribute.

Of course, you can use it for changing any other attribute as well, especially when using 'hash' => 'clear'. But this is out of scope for this PR, as I said:

You can use it also for updating user information, but I do not think this would be very user friendly.

The main focus was on the case of needing hashes that are known to be insecure. It is rather odd that you are in need for them for two different use cases, but of course this can happen. But this can be clarified to the user with the label key.

If it is in general that you do not like the term "application" used in the documentation and in the coding, please tell me, I do not know what else I should call it... Maybe Custom Password Field? But how should the web form clarify for what?

These are my thinkings right now, maybe I come to a better solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replaced apppwd with custompwdfield, in code and documentation.

These were some groundbreaking changes, please give me some time testing everything if everything is still working as expected.

.. tip:: If you do not set an Arraykey in this configuration, the settings for the
main password will be applied!

For more information, follow the steps mentioned below.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please fix the README with more generic terms. (see comment above)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@@ -0,0 +1,225 @@
<?php

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor your PR on top of the master branch.

This requires some work.

Take care that there have been evolutions since then:

  • externalize ldap function to \Ltb\Ldap library. see changes in change.php file
  • adding translations to lang/ files
  • adding some features (ppolicy criteria)

Also, there are a lot of code duplication here. Maybe we could factorize more things, but currently I don't know how.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I know. My fork somehow has to get the code of master. It has been a long time since I was looking on this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a local branch from ltb-project:master and merged it locally to markus-96:1.5, then resolved the conflicts.

I have to delete my fork so that I can fork from master directly, hopefully this PR is closed as soon as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

* adding some features (ppolicy criteria)

For entropy checks:
This can not be done between "app"-passwords and the user-password, because on the app-password side you need to know the old password, which you do not. So: While changing the "app"-password, you can check the entropy between "app"-password and user-password, but if you change the user-password, you can not check the entropy to the already set "app"-password. So this check is useless in this aspect.

I will try to adopt the added .js-functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be resolved now

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

Thanks for the taking into consideration my remarks. Globally, it is much better.

Your branch 1.5 and origin/master are in conflict, and furthermore you rebase in the wrong direction. This makes the rebase very complicated, so I preferred to do a global patch from your branch, and apply it to the master branch.

See this issue for referencing the feature: #864
And this new MR for continuing the work: #865

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

Thanks for creating the new branch. But I have some problem:

I can not push to change-custom-password-fields, how should I continue working on this? Should I create a new fork and create PRs for every commit to change-custom-password-fields?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,

Thanks for creating the new branch. But I have some problem:

I can not push to change-custom-password-fields, how should I continue working on this? Should I create a new fork and create PRs for every commit to change-custom-password-fields?

You could clone again or synchronize your personal repository, work on your local change-custom-password-fields branch, and propose a PR to self-service-password change-custom-password-fields branch

$change_apppwd_labels[$i] = array();
$change_apppwd_labels[$i]['label'] = $change_apppwd[$i]['label'];
$change_apppwd_labels[$i]['msg_changehelpextramessage'] = $change_apppwd[$i]['msg_changehelpextramessage'];
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The password-app button is not displayed like the others, and seems ugly. (see capture)
ssp-passwordapp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this with the new version of bootstrap? It is not included in my PR yet, it was working with bootstrap v3.4.1, this seams to be bootstrap 5.3.1. Am I right?
Here, it looks like the following:
grafik

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be resolved now

* @param array $hash_options additional options to be used by the hashing algorithm
* @return string
*/
function make_password($password, $hash, $hash_options): string {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typically, I think that these functions should go into https://github.com/ltb-project/ltb-ldap

@coudot what is your opinion on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
}
}
$hash = get_hash_type($ldap, $dn, $pwd_attribute);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above: I think these functions should go into https://github.com/ltb-project/ltb-ldap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above: see ltb-project/ltb-common#7

><i class="fa fa-fw fa-terminal"></i> {$msg_menuapppwd|cat:$app.label} </a>
</li>
{/foreach}
{/if}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above: the password-app button is not displayed like the others, and seems ugly. (see capture)

ssp-passwordapp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, I did not yet adopt it to bootstrap 5.3.1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be resolved now

still a lot of work to do
@markus-96 markus-96 changed the base branch from 1.5 to master March 6, 2024 18:30
Markus Beckschulte added 8 commits March 7, 2024 17:12
This reverts commit 109b926.
in the form, I had to use the same ids as in change.tpl for the ppolicy js to work.
Also, I have to reuse the policy config variables.
@markus-96 markus-96 changed the title feature: ability to change app passwords feature: ability to change custom password fields Mar 10, 2024
@davidcoutadeur
Copy link

I have reworked this PR in #865

See this PR for next discussions and comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants