Skip to content

Commit bd2c116

Browse files
committed
ZxcvbnKeyAnalyzer fix in case on dep error
1 parent 087db06 commit bd2c116

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/Component/KeyManagement/Analyzer/ZxcvbnKeyAnalyzer.php

+23-19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use function is_string;
88
use Jose\Component\Core\JWK;
99
use ParagonIE\ConstantTime\Base64UrlSafe;
10+
use Throwable;
1011
use ZxcvbnPhp\Zxcvbn;
1112

1213
final class ZxcvbnKeyAnalyzer implements KeyAnalyzer
@@ -27,25 +28,28 @@ public function analyze(JWK $jwk, MessageBag $bag): void
2728
return;
2829
}
2930
$zxcvbn = new Zxcvbn();
30-
$strength = $zxcvbn->passwordStrength($k);
31-
32-
switch (true) {
33-
case $strength['score'] < 3:
34-
$bag->add(
35-
Message::high(
36-
'The octet string is weak and easily guessable. Please change your key as soon as possible.'
37-
)
38-
);
39-
40-
break;
41-
42-
case $strength['score'] === 3:
43-
$bag->add(Message::medium('The octet string is safe, but a longer key is preferable.'));
44-
45-
break;
46-
47-
default:
48-
break;
31+
try {
32+
$strength = $zxcvbn->passwordStrength($k);
33+
switch (true) {
34+
case $strength['score'] < 3:
35+
$bag->add(
36+
Message::high(
37+
'The octet string is weak and easily guessable. Please change your key as soon as possible.'
38+
)
39+
);
40+
41+
break;
42+
43+
case $strength['score'] === 3:
44+
$bag->add(Message::medium('The octet string is safe, but a longer key is preferable.'));
45+
46+
break;
47+
48+
default:
49+
break;
50+
}
51+
} catch (Throwable) {
52+
$bag->add(Message::medium('The test of the weakness cannot be performed.'));
4953
}
5054
}
5155
}

0 commit comments

Comments
 (0)