aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
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.")
+ }
}
}