aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-03-22 20:18:14 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-03-22 20:18:14 +0100
commit09f5b7f0eb6117a6cfc915a359042faff01f2dee (patch)
treed43d33f7d31eb0e14ed4867a125961f6f9eed0ea /src
parente397107b65258f81b69f43050b503bc8f8756697 (diff)
downloadcheckpw-09f5b7f0eb6117a6cfc915a359042faff01f2dee.tar.gz
checkpw-09f5b7f0eb6117a6cfc915a359042faff01f2dee.tar.bz2
checkpw-09f5b7f0eb6117a6cfc915a359042faff01f2dee.zip
Move reporting of pwned or not into main.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs
index 3f82135..4e7cbb7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,6 +17,7 @@
extern crate reqwest;
extern crate ring;
use std::env;
+use std::error::Error;
use ring::digest;
//
@@ -75,17 +76,20 @@ fn test_creating_new_password() {
assert_eq!(&pw.rest, "910077770C8340F63CD2DCA2AC1F120444F");
}
-fn check(pw: Password) {
+fn check(pw: Password) -> Result<bool, reqwest::Error>{
let uri = &format!("https://api.pwnedpasswords.com/range/{}", pw.range);
- let hashes = reqwest::get(uri).unwrap().text().unwrap();
+ let hashes = reqwest::get(uri)?.text()?;
if let Some(pos) = hashes.find(&pw.rest) {
- println!("Password is PWNED!");
if let Some(res) = hashes[pos..].lines().take(1).collect::<Vec<_>>().pop() {
let count = res.split(':').skip(1).collect::<Vec<_>>().pop().unwrap();
println!("The password {} was found in {} breaches", pw.pw, count);
}
+
+ return Ok(true);
}
+
+ Ok(false)
}
fn print_usage() {
@@ -103,6 +107,10 @@ fn main() {
}
for pw in passwords {
- check(Password::new(&pw));
+ match check(Password::new(&pw)) {
+ Err(e) => println!("{}", e.description()),
+ Ok(true) => println!("Password is PWNED!"),
+ Ok(false) => println!("Password was not found in any breaches.")
+ }
}
}