PasswordGeneratorSettingsDto.php needs bool typecasts to work

As a CE Admin I don’t appear to have a way to set a default password configuration (I like to have 26 chars instead of 18, and remove of few of the difficult to read character classes) so I don’t have to set them each time. I understand as adin in Pro Edition you can do this.

I’m reporting this because until I observed how you did a typecase on instantiation of the object, you didn’t do it in this Model/Dto initialization code. When I added the bool and int typecasts (and my additional tweaks for a default) … it all works now.

I tried to report this in the github but you have to be a “collaborator” to do a pull request (which I am not at this time).

Here is my diff of the file I changed at:

/usr/share/php/passbolt/plugins/PassboltCe/PasswordPolicies/src/Model/Dto/PasswordGeneratorSettingsDto.php (nice!)

diff PasswordGeneratorSettingsDto.php.orig PasswordGeneratorSettingsDto.php

156,167c156,167
< ‘length’ => 18,
< ‘mask_upper’ => true,
< ‘mask_lower’ => true,
< ‘mask_digit’ => true,
< ‘mask_parenthesis’ => true,
< ‘mask_emoji’ => false,
< ‘mask_char1’ => true,
< ‘mask_char2’ => true,
< ‘mask_char3’ => true,
< ‘mask_char4’ => true,
< ‘mask_char5’ => true,
< ‘exclude_look_alike_chars’ => true,

        'length' => (int)26,
        'mask_upper' => (bool)true,
        'mask_lower' => (bool)true,
        'mask_digit' => (bool)true,
        'mask_parenthesis' => (bool)false,
        'mask_emoji' => (bool)false,
        'mask_char1' => (bool)true,
        'mask_char2' => (bool)false,
        'mask_char3' => (bool)false,
        'mask_char4' => (bool)true,
        'mask_char5' => (bool)true,
        'exclude_look_alike_chars' => (bool)true,

179,190c179,190
< ‘length’ => $this->length,
< ‘mask_upper’ => $this->mask_upper,
< ‘mask_lower’ => $this->mask_lower,
< ‘mask_digit’ => $this->mask_digit,
< ‘mask_parenthesis’ => $this->mask_parenthesis,
< ‘mask_emoji’ => $this->mask_emoji,
< ‘mask_char1’ => $this->mask_char1,
< ‘mask_char2’ => $this->mask_char2,
< ‘mask_char3’ => $this->mask_char3,
< ‘mask_char4’ => $this->mask_char4,
< ‘mask_char5’ => $this->mask_char5,
< ‘exclude_look_alike_chars’ => $this->exclude_look_alike_chars,

        'length' => (int)$this->length,
        'mask_upper' => (bool)$this->mask_upper,
        'mask_lower' => (bool)$this->mask_lower,
        'mask_digit' => (bool)$this->mask_digit,
        'mask_parenthesis' => (bool)$this->mask_parenthesis,
        'mask_emoji' => (bool)$this->mask_emoji,
        'mask_char1' => (bool)$this->mask_char1,
        'mask_char2' => (bool)$this->mask_char2,
        'mask_char3' => (bool)$this->mask_char3,
        'mask_char4' => (bool)$this->mask_char4,
        'mask_char5' => (bool)$this->mask_char5,
        'exclude_look_alike_chars' => (bool)$this->exclude_look_alike_chars,

Interested to see what you think and if you like I could add it to a pull request if you want to make the change to your source code (you probably don’t want to use my tweaks) :slight_smile:

Hey @janoah, welcome to the passbolt community forum :wave:

When I added the bool and int typecasts (and my additional tweaks for a default) … it all works now.

Can you explain a but what type of tweaks you are trying to do? and also use-case, etc. Basically if you are doing the tweaks then you can also do tweaks in other (the file you’ve suggested) files as well.

Also, without this diff changes what error are you facing?

Regarding doing 'length' => (int)26, this seems to be unnecessary because 26 itself is integer so not sure why you want that.

As I mentioned in the opening of this message:

[quote]As a CE Admin I don’t appear to have a way to set a default password configuration (I like to have 26 chars instead of 18, and remove of few of the difficult to read character classes) so I don’t have to set them each time. I understand in in Pro Edition you can do this.
[/quote]

I want to set the default password. If I change the code as it is written without typecasts it doesn’t do anything. With the type casts, I get the higher security level settings. I got the idea from how the code is already written (probably because it has no affect without the initialization with type casts).

The diff I showed is the only change I made. It accomplishes the task I wanted to accomplish which was to change the default password configuration so I don’t have to reset it every time to a higher level of password protection (plus remove some of the characters that are hard to read).

I’m not facing an error as it is written. I’m just pointing out that if you actually want the code to affect the program, these type casts need to be in place.

All I can think of is if it’s the first initialization, PHP may need help to determine what type to assign the variable. As I said, I observed this code in other places in the code, and tried it since any previous changes I was doing were not having any affect.

Hey @janoah, if you change any code directly unfortunately we can’t help you there.

If you want convenience to set default password configuration, I would invite you to try our Pro version which provides Password Policies (Password Policy | Passbolt documentation.).

I’ve noted your use-case, I will try to raise to our team and check if we can provide something similar in CE. But it’s unlikely to happen anytime soon.

Thank you for your response. I think passbolt is great! Have a great day!

1 Like