Skip to content

Commit 747f3b3

Browse files
committed
crypto.bcrypt: reduce runtime cost for running bcrypt_test.v, by reducing the iteration count
1 parent b656481 commit 747f3b3

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

vlib/crypto/bcrypt/bcrypt_test.v

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
import crypto.bcrypt
22

33
fn test_crypto_bcrypt() {
4-
bcrypt.compare_hash_and_password('123456'.bytes(), '$2y$13$7j2kgHgrEiI9kYmiXZuiyu3IJFWXEH.sZN6ai82XNCd9SZ7UwdlTW'.bytes()) or {
5-
panic(err)
6-
}
7-
8-
hash := bcrypt.generate_from_password('password'.bytes(), 10) or { panic(err) }
4+
bcrypt.compare_hash_and_password('123456'.bytes(), r'$2a$07$MRniCPEgEQnrJmmgN.maM.kF2a/TI2PB37EQQNsUtEuINwultcHTm'.bytes())!
95

10-
bcrypt.compare_hash_and_password('password'.bytes(), hash.bytes()) or { panic(err) }
6+
hash := bcrypt.generate_from_password('password'.bytes(), 5)!
7+
bcrypt.compare_hash_and_password('password'.bytes(), hash.bytes())!
118

129
bcrypt.compare_hash_and_password('password2'.bytes(), hash.bytes()) or {
1310
assert err.msg() == 'mismatched hash and password'
1411
}
1512

16-
hash2 := bcrypt.generate_from_password('bb'.bytes(), 10) or { panic(err) }
13+
hash2 := bcrypt.generate_from_password('bb'.bytes(), 5)!
1714
mut hash2_must_mismatch := false
18-
1915
bcrypt.compare_hash_and_password('bbb'.bytes(), hash2.bytes()) or {
2016
hash2_must_mismatch = true
2117
assert err.msg() == 'mismatched hash and password'

0 commit comments

Comments
 (0)