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

[Config] Add password algorithm selector #9468

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

skarya22
Copy link
Contributor

@skarya22 skarya22 commented Nov 14, 2024

Brief summary of changes

  • In CCNA, we use PASSWORD_ARGON2I rather than PASSWORD_DEFAULT
  • This PR adds an option to change which php password algorithm to use so that projects do not need an override in-order to change it.
  • It defaults to PASSWORD_DEFAULT which is what it was set to before.
    image

Testing instructions (if applicable)

  1. Try changing the password hash in config, and then setting a new password.
  2. See that you can still login

@skarya22 skarya22 added the Priority: Projects PR or issue is a priority for at least one project and should be a higher priority for LORIS label Nov 14, 2024
@@ -88,6 +88,14 @@ class Configuration extends \NDB_Form
'emergency' => 'Emergency',
];

$this->tpl_data['password_algos'] = [
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you use https://www.php.net/manual/en/function.password-algos.php (and add a "Default" option)

I'm not really sure what the point of having the blank option here is.

Copy link
Contributor Author

@skarya22 skarya22 Nov 14, 2024

Choose a reason for hiding this comment

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

That function doesn't output usable strings for the password_hash function unfortunately. It gives values such as: '2y','argon2i, 'argon2id', but password_hash uses, 'PASSWORD_DEFAULT','PASSWORD_BCRYPT', 'PASSWORD_ARGON2I', and 'PASSWORD_ARGON2ID'

I will remove the blank option though. It was just there in-case somehow a non-usable value was saved so it doesn't show PASSWORD_DEFAULT instead. But it probably just makes it confusing

Copy link
Collaborator

Choose a reason for hiding this comment

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

PASSWORD_DEFAULT/PASSWORD_BCRYPT/etc are just built in constants with those values.

$ php -a
Interactive shell

php > print PASSWORD_DEFAULT;
2y
php > print PASSWORD_ARGON2I;
argon2i
php > print_r(password_algos());
Array
(
    [0] => 2y
    [1] => argon2i
    [2] => argon2id
)
php > print password_hash('test', 'argon2i');
$argon2i$v=19$m=65536,t=4,p=1$WlBObVNleHU0RHVCMG9DTw$3jZ/HN8N4r6YERoJJbMGup/d8rebjUZ72lYZcbTsjno
php > 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh sweet, thanks!

@skarya22
Copy link
Contributor Author

@kongtiaowang I can't seem to get the tests to work in the Password class due to the addition of a getSetting from the Config table in Password. How can I setup the mock table in the test to have a value for Config?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Projects PR or issue is a priority for at least one project and should be a higher priority for LORIS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants