Swift library for haveibeenpwned.com using APIv3
Notes: Some API request needs a paid API key
- iOS 8.0+ / macOS 10.10+
- Swift 5+
CocoaPods is a dependency manager for Cocoa projects.
Podfile
:
pod 'HaveIBeenPwned'
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
Cartfile
:
github "vhosune/HaveIBeenPwned"
- Check if a password has already been pwned in a breach
import HaveIBeenPwned
// init HaveIBeenPwned with its Settings
let pwned = HaveIBeenPwned(with: HaveIBeenPwned.Settings())
// create a request
if let request = pwned.requestSearch(password: "password") {
// fetch the request
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
// parse the result
let result = pwned.parseResponse(data, response, error)
// handle the parsed result
if case .passwords(let ranges) = try? result.get() {
let count = HaveIBeenPwned.search(for: "password", in: ranges)
print("has been pwned \(count) times")
}
}
task.resume()
}
- Check if a site has been breached
let request = pwned.requestBreach(name: "yahoo")
- Check if a user account appears in a breach
// init HaveIBeenPwned with its Settings and the Api key
let pwned = HaveIBeenPwned(with: HaveIBeenPwned.Settings(apiKey: "YOUR_API_KEY"))
let request = pwned.requestBreached(account: "user@example.com")