File tree Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Expand file tree Collapse file tree 1 file changed +4
-8
lines changed Original file line number Diff line number Diff line change 1
1
import crypto.bcrypt
2
2
3
3
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 ())!
9
5
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 ())!
11
8
12
9
bcrypt.compare_hash_and_password ('password2' .bytes (), hash.bytes ()) or {
13
10
assert err.msg () == 'mismatched hash and password'
14
11
}
15
12
16
- hash2 := bcrypt.generate_from_password ('bb' .bytes (), 10 ) or { panic (err) }
13
+ hash2 := bcrypt.generate_from_password ('bb' .bytes (), 5 ) !
17
14
mut hash2_must_mismatch := false
18
-
19
15
bcrypt.compare_hash_and_password ('bbb' .bytes (), hash2 .bytes ()) or {
20
16
hash2_must_mismatch = true
21
17
assert err.msg () == 'mismatched hash and password'
You can’t perform that action at this time.
0 commit comments