- cfpassphrase/test/Pbkdf2Test.cfc
- master
- 1 KB
- 53
1<cfcomponent extends="TestBase">
2<cfscript>
3
4 function init( IncludeSlowTests )
5 {
6 super.init( argumentcollection=arguments );
7
8 this.Name = 'pbkdf2';
9
10 super.start();
11
12 this.test_info();
13
14 if ( IncludeSlowTests )
15 this.test_basic();
16 else
17 skip( 30 );
18
19 return super.end();
20 }
21
22
23 function test_info( TestData )
24 {
25 var info2 = PassphraseInfo('180:5fabd8b160f5f9225ec5569ce2f02d5a2e29a29e0b280614:d11a602ecc7830280b25cdd29b539e9e0f8438a0a43e6637');
26 assertEqual(info2.Algorithm,'PBKDF2');
27 assertEqual(info2.Status,'Supported');
28 assertEqual(info2.Iterations,180);
29 assertEqual(info2.Salt,'5fabd8b160f5f9225ec5569ce2f02d5a2e29a29e0b280614');
30 assertEqual(info2.Hash,'d11a602ecc7830280b25cdd29b539e9e0f8438a0a43e6637');
31 assertEqual(StructCount(info2),5);
32 }
33
34
35 function test_basic()
36 {
37 for ( var i=0 ; i<10 ; ++i )
38 {
39 var password = ""&i;
40 var hash = PassphraseHash(password,'pbkdf2');
41 var secondHash = PassphraseHash(password,'pbkdf2');
42
43 assertNotEqual( hash , secondHash , "Two hashes are equal." );
44
45 var wrongPassword = ""&(i+1);
46 assertFalse( PassphraseCheck(wrongPassword,hash) , "Wrong password accepted." );
47
48 assertTrue( PassphraseCheck(password,hash) , "Good password not accepted." );
49 }
50 }
51
52
53</cfscript>
54</cfcomponent>