-
Notifications
You must be signed in to change notification settings - Fork 1
/
saltAndHashTests.cfc
25 lines (15 loc) · 1.09 KB
/
saltAndHashTests.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<cfcomponent name="saltAndHashTests" extends="mxunit.framework.TestCase" output="false">
<cffunction name="simpleSaltAndHashTest" access="public">
<cfset var i = 0 />
<cfset var local = structNew() />
<cfset var saltAndHasher = createObject("component","aemis.com.saltAndHash").init() />
<cfloop from="1" to="10" index="i">
<cfset local.password = i />
<cfset local.hash = saltAndHasher.saltAndHash(local.password) />
<cfset local.secondHash = saltAndHasher.saltAndHash(local.password) />
<cfset assertFalse(local.hash.hashedString EQ local.secondHash.hashedString, "failure: hashes are equal! on iteration #i#")>
<cfset assertFalse(saltAndHasher.validateHashedString(local.password & i, local.hash.salt, local.hash.hashMethod, local.hash.hashedString), "failure: validated the hash on the wrong password! on iteration #i#")>
<cfset assertTrue(saltAndHasher.validateHashedString(local.password, local.hash.salt, local.hash.hashMethod, local.hash.hashedString), "failure: unable to validate the hash! on iteration #i#")>
</cfloop>
</cffunction>
</cfcomponent>