-
Notifications
You must be signed in to change notification settings - Fork 38
Add Argon2i for password hashing #58
base: develop
Are you sure you want to change the base?
Add Argon2i for password hashing #58
Conversation
I've refactored out the usage of the default constants but it seems like the PHP7.2 binaries from travis-ci have no argon2 support whatsoever, see: travis-ci/travis-ci#8863 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MatthiasKuehneEllerhold please base this on top of develop
, which is where new features should land 👍
src/Password/Argon2i.php
Outdated
); | ||
} | ||
|
||
if (! empty($options)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverse the conditional to return early
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/Password/Argon2i.php
Outdated
* @param array|Traversable $options | ||
* @throws Exception\InvalidArgumentException | ||
*/ | ||
public function __construct($options = []) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ezimuel can we get rid of this kind of un-typed ctors?
src/Password/Argon2i.php
Outdated
* | ||
* @return Argon2i | ||
*/ | ||
public function setMemoryCost($memoryCost) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't expose any of these setter/getters anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius I think we still need this in order to be compliant with the previous implementations like Zend\Crypt\Password\Bcrypt
, Zend\Crypt\Password\BcryptSha
and Zend\Crypt\Password\Apache
.
Even, because we can add some check on setter to verify that the parameter is correct with a detailed error message if not. IMHO, this is actually one of the advantages to use a wrapper class like Argon2i
instead of the PHP bult-in function.
Rebased it unto develop and changed the PR target. I've tried to orient myself on the existing bcrypt class. |
No worries, I'm just suggesting to get rid of some cruft, especially on new classes. @ezimuel needs to check these, since he's the lead here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MatthiasKuehneEllerhold thanks for this PR and sorry for the delay in reviewing. I provide my feedbakcs, please check and let me know. Thanks again for your great work!
src/Password/Argon2i.php
Outdated
* | ||
* @return Argon2i | ||
*/ | ||
public function setMemoryCost($memoryCost) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius I think we still need this in order to be compliant with the previous implementations like Zend\Crypt\Password\Bcrypt
, Zend\Crypt\Password\BcryptSha
and Zend\Crypt\Password\Apache
.
Even, because we can add some check on setter to verify that the parameter is correct with a detailed error message if not. IMHO, this is actually one of the advantages to use a wrapper class like Argon2i
instead of the PHP bult-in function.
src/Password/Argon2i.php
Outdated
* | ||
* @var int|null | ||
*/ | ||
protected $memoryCost; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will suggest to assign the default PHP values for $memoryCost
, $timeCost
and $threads
. Using the constants:
PASSWORD_ARGON2_DEFAULT_MEMORY_COST
PASSWORD_ARGON2_DEFAULT_TIME_COST
PASSWORD_ARGON2_DEFAULT_THREADS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the constants on PHP < 7.2 leads to an "Undefined constant" error even if you just autoload the class. (See the <7.2 Unit-Tests).
{ | ||
$options = []; | ||
|
||
if ($this->memoryCost !== null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use the default PHP values, we can omit this check with null values and always pass the $options
to password_hash
.
src/Password/Argon2i.php
Outdated
* | ||
* @return Argon2i | ||
*/ | ||
public function setTimeCost($timeCost) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check the value of $timeCost
and verify that is allowed values for $options
in password_hash()
. As commented before, we should offer a safe way to use the Argon2i parameter with a detailed message in case of invalid values.
@MatthiasKuehneEllerhold I forgot to answer to your main questions:
|
This repository has been closed and moved to laminas/laminas-crypt; a new issue has been opened at laminas/laminas-crypt#1. |
This repository has been moved to laminas/laminas-crypt. If you feel that this patch is still relevant, please re-open against that repository, and reference this issue. To re-open, we suggest the following workflow:
|
This PR adds an extra class for the argon2i password hash algorithm introduced with PHP7.2.
There are some open questions with this:
Do we really want to have 1 new class for each algorithm PHP addes? "Argon2id" is just around the corner...
PHP's
password_verify()
accepts currently both Bcrypt and Argon2i hashes. So basically you could either use theBcrypt
class or theArgon2i
class to verify either hashes.This makes it pretty easy to migrate users from Bcrypt to Argon2i:
Argon2i
class as the dependencyDo we need a wrapper function for
password_needs_rehash()
? This would mean we need some kind of inter-class upgrade path (from classBcrypt
toArgon2i
in future php-versions).Although we dont know WHY
password_needs_rehash()
returns false: is it because of the algorithm or the cost value(s)?This class is marked as PHP7.2+ only (it throws an exception in the constructor). Do we want to provide fallbacks of some kind for older PHP Versions?
Other than the algorithm no other PHP7.2+ specific features were used in this class (e. g. scalar type hints and return types) because a syntax error is much more heavy and harder to catch than a constructor-exception (Pre 7.0).
Should type hints and return types get added because its a PHP7.2+ class anyway?