summary refs log tree commit diff stats
path: root/doc
Commit message (Collapse)AuthorAgeFilesLines
* todo: added more info on bug #31hut2010-01-091-0/+5
|
* random cleanups and fixeshut2010-01-071-5/+6
|
* new minor version v1.0.1hut2010-01-022-4/+4
|
* updated pydoc documentationhut2010-01-0248-788/+3167
|
* notify: merged into statusbar, allow to view the log in the pagerhut2010-01-013-35/+2
|
* cleanupshut2009-12-311-1/+5
|
* rename filelist(container) to browsercolumn/browserviewhut2009-12-313-38/+76
|
* updated uml projecthut2009-12-305-73/+215
|
* shorten comment in ranger.pyhut2009-12-261-0/+4
|
* moved /uml to /doc/umlhut2009-12-2514-0/+2180
|
* Explained cd-after-exit featurehut2009-12-251-0/+132
|
* moved pydoc pages to doc/pydochut2009-12-2565-0/+0
|
* updated pydoc pageshut2009-12-2565-0/+10505
.vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
package hibp

import (
	"fmt"
	"strings"
)

// GetPwned takes SHA-1 Hash as input & returns Pwned Passwords list
// returned by the Have I Been Pwned API
func GetPwned(hsh string) (map[string]string, error) {
	api := "https://api.pwnedpasswords.com/range"
	list := make(map[string]string)

	pfx := hsh[:5]

	reqApi := fmt.Sprintf("%s/%s", api, pfx)
	body, err := reqHIBP(reqApi)
	if err != nil {
		return list, fmt.Errorf("reqHIBP failed\n%s",
			err.Error())
	}

	for _, v := range strings.Split(body, "\r\n") {
		s := strings.Split(v, ":")
		list[s[0]] = s[1]
	}
	return list, err
}

// ChkPwn takes list, hash as input & returns if the hash is in list,
// the frequency
func ChkPwn(list map[string]string, hsh string) (bool, string) {
	sfx := hsh[5:]
	for k, fq := range list {
		if sfx == k {
			return true, fq
		}
	}
	return false, ""
}