// checkpw - Check passwords against pwnedpasswords.com // Copyright (C) 2018 Harald Eilertsen // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . use checkpw::{check, Password}; use std::{env, error::Error, process, thread, time}; fn print_usage() { println!("Usage: checkpw ..."); } fn main() { let (args, passwords): (Vec, Vec) = env::args().skip(1).partition(|arg| arg.starts_with('-')); if args.is_empty() && passwords.is_empty() { print_usage(); return; } let mut first_round = true; let mut pwn_count = 0; for pw in passwords { if first_round { first_round = false; } else { thread::sleep(time::Duration::new(1, 0)); } match check(Password::new(&pw)) { Err(e) => println!("{}", e.description()), Ok(num) => { if num > 0 { println!("Password is PWNED! It was found in {} breaches.", num); pwn_count += 1; } else { println!("Password was not found in any breaches"); } } } } process::exit(pwn_count); }