This class indicates if a password is found in the "Have I Been Pwned?" collection of passwords, using the V2 API. Read more about this database and API in this blog post.
Specifically, this code uses the range
portion of the API, so the password itself is not sent over the Interwebs.
Only the first 5 characters of the SHA-1 has is sent to the server, which sends back a list of possible
matches. This way, the password itself is not leaked.
io.reactivex.rxjava2:rxjava:2.1.7
(or compatible), com.squareup.okhttp3:okhttp:3.9.1
(or compatible),
and the INTERNET
permission (on Android).
Create a PwnedCheck
instance, supplying an OkHttpClient
configured as you like. Call validate()
,
supplying the passphrase to check, and observe the result:
PwnedCheck checker=new PwnedCheck(new OkHttpClient());
checker.validate("password")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(count -> ..., throwable -> ...);
0
indicates that the password hash did not match anything in the collection. A positive integer is the number of times that
password was found in the collection, so higher numbers means a more popularly-used password. For example, password
appears
3303003 times, as of when I wrote this code snippet.
This code is licensed under the Apache License, Version 2.0.
Subscribe to the Warescription and ask me in an office hours chat.
Or, try Stack Overflow.