2021-11-28 13:40:50 +03:00
|
|
|
import crypto.bcrypt
|
|
|
|
|
|
|
|
fn test_crypto_bcrypt() {
|
|
|
|
hash := bcrypt.generate_from_password('password'.bytes(), 10) or { panic(err) }
|
|
|
|
|
|
|
|
bcrypt.compare_hash_and_password('password'.bytes(), hash.bytes()) or { panic(err) }
|
|
|
|
|
|
|
|
bcrypt.compare_hash_and_password('password2'.bytes(), hash.bytes()) or {
|
2022-02-11 16:52:33 +03:00
|
|
|
assert err.msg() == 'mismatched hash and password'
|
2021-11-28 13:40:50 +03:00
|
|
|
}
|
2022-12-31 18:18:43 +03:00
|
|
|
|
|
|
|
hash2 := bcrypt.generate_from_password('bb'.bytes(), 10) or { panic(err) }
|
|
|
|
mut hash2_must_mismatch := false
|
|
|
|
|
|
|
|
bcrypt.compare_hash_and_password('bbb'.bytes(), hash2.bytes()) or {
|
|
|
|
hash2_must_mismatch = true
|
|
|
|
assert err.msg() == 'mismatched hash and password'
|
|
|
|
}
|
|
|
|
|
|
|
|
assert hash2_must_mismatch
|
2021-11-28 13:40:50 +03:00
|
|
|
}
|