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

Passwords: Fix for validation of cost 31 [Closes #2] #4

Closed
wants to merge 2 commits into from
Closed

Passwords: Fix for validation of cost 31 [Closes #2] #4

wants to merge 2 commits into from

Conversation

josefsabl
Copy link
Contributor

No description provided.

@fprochazka
Copy link
Contributor

Do you think you could add a test case?

http://phpfashion.com/jak-komitovat-se-zarucni-smlouvou

@josefsabl
Copy link
Contributor Author

Hehe, I thought someone will probably ask.

Well, I had the test written before the fix. I actually am fan of TDD.

$h = Passwords::hash('dg', array('cost' => 31));
Assert::true(Passwords::verify('dg', $h));

It would verify that the bug is there in the first place.

But after some time of wondering why tests seem to not run at all, it turns out computers have hard time calculating hash with cost 31 and the test would never complete on my PC, so I just deleted it.

I think it's not worth the trouble for such a trivial thing.

@josefsabl
Copy link
Contributor Author

Anyway, I read that article by dg last week and use it to advocate unit testing in our company ;-)

@@ -54,7 +54,7 @@ public static function hash($password, array $options = NULL)
public static function verify($password, $hash)
{
return preg_match('#^\$2y\$(?P<cost>\d\d)\$(?P<salt>.{22})#', $hash, $m)
&& $m['cost'] > 3 && $m['cost'] < 31
&& $m['cost'] >= 4 && $m['cost'] <= 31
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 think it is better to use same magic numbers everywhere and use >= instead of > as it is less confusing and error prone.

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

Successfully merging this pull request may close these issues.

None yet

2 participants