-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHIBP.cfc
More file actions
49 lines (45 loc) · 2.11 KB
/
Copy pathHIBP.cfc
File metadata and controls
49 lines (45 loc) · 2.11 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!---
--- HIBP
--- ----
---
--- author: jaybigam
--- date: 3/6/18
--- Anyone wants to provide improved regex string parsing...have at er.
--->
<cfcomponent accessors="true" output="false" persistent="false">
<cffunction name="pwnChk" returntype="string">
<cfargument name="pwd" required="true">
<cfset local.prefix = left(hash(arguments.pwd, "SHA"),5)>
<cfset local.suffix = right(hash(arguments.pwd, "SHA"),5)>
<cfhttp url="https://api.pwnedpasswords.com/range/#local.prefix#" method="get" userAgent="CFML_PwnChk" >
</cfhttp>
<cfset local.re2 = local.suffix>
<CFSET local.string = cfhttp.filecontent>
<!--- find position of suffix occurence --->
<cfset local.posSuffix=FindNoCase(local.RE2,local.String)>
<cfif local.posSuffix neq 0>
<!--- hashes are 40chars, the first 5 are stripped, the last 5 are result --->
<cfset local.startPos = local.posSuffix-30>
<cfset local.hashMatch = mid (local.string, local.startPos, 35)>
<!--- get the match plus 20 extra characters which wil capture the pwned count --->
<cfset local.pwnCTSpacePos=mid (local.string, local.startPos, 55)>
<!--- We look for : and a carriage return chr(13) which is so we can capture the variable pwned count length --->
<cfset local.re1 = ":">
<cfset local.re2 = chr(13)>
<!--- Position of : --->
<cfset local.startPos=REFindNoCase(local.RE1,local.pwnCTSpacePos)>
<!--- Postion of chr(13) --->
<cfset local.crPos=REFindNoCase(local.RE2,local.pwnCTSpacePos)>
<!--- strip the : --->
<cfset local.pos = left(local.pwnCTSpacePos, local.crPos-1)>
<!--- get the pwned Count --->
<cfset local.pwnCtSpacePos = right(local.pos, len(local.pos)-local.startPos)>
<cfset local.result="Attention: The password you have chosen is known exist in data breach(es) on another site(s).<br>
It has been compromised <b>#local.pwnCtSpacePos#</b> times. It should be considered insecure.<br>
If you use this password on other sites, you should consider changing it.">
<cfelse>
<cfset local.result="OK">
</cfif>
<cfreturn local.result>
</cffunction>
</cfcomponent>