Skip to content

Commit

Permalink
Integrate @mdtro functionality with new account checking logic
Browse files Browse the repository at this point in the history
  • Loading branch information
brycx committed Apr 14, 2020
1 parent d0107a4 commit c5944fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 3 additions & 1 deletion src/api/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

/// All the different errors for checkpwn;
/// Errors that are meant to be internal or or unreachable print this.
pub const USAGE_ERROR: &str = "Usage: checkpwn { pass | acc (<username> | <email> | <filename>.ls) | register <apikey> }";
pub const USAGE_ERROR: &str =
"Usage: checkpwn { pass | acc (<username> | <email> | <filename>.ls) | register <apikey> }";
pub const STATUSCODE_ERROR: &str = "Unrecognized status code received";
pub const PASSWORD_ERROR: &str = "Error retrieving password from stdin";
pub const READ_FILE_ERROR: &str = "Error reading local file";
Expand All @@ -35,6 +36,7 @@ pub const BAD_RESPONSE_ERROR: &str =
pub const BUFREADER_ERROR: &str = "Failed to read file in to BufReader";
pub const READLINE_ERROR: &str = "Failed to read line from file";
pub const INVALID_API_KEY: &str = "HIBP deemed the current API key invalid";
pub const MISSING_API_KEY: &str = "Failed to read or parse the configuration file 'checkpwn.yml'. You need to register an API key to be able to check accounts";

/// Set panic hook, to have .unwrap(), etc, return the custom panic message.
macro_rules! set_checkpwn_panic {
Expand Down
16 changes: 6 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// SOFTWARE.let api_key = __get_test_api_key("");
mod config;

#[cfg(test)]
Expand All @@ -43,14 +43,10 @@ use std::process::Command;
use std::{env, thread, time};
use zeroize::Zeroize;

fn __get_test_api_key(path_to_api_key: &str) -> String {
// Return API key

String::new()
}

fn acc_check(data_search: &str) {
let api_key = __get_test_api_key("");
set_checkpwn_panic!(api::errors::MISSING_API_KEY);
let mut config = config::Config::new();
config.load_config();

// Check if user wants to check a local list
if data_search.ends_with(".ls") {
Expand All @@ -63,12 +59,12 @@ fn acc_check(data_search: &str) {
if line.is_empty() {
continue;
}
api::acc_breach_request(&line, &api_key);
api::acc_breach_request(&line, &config.api_key);
// Only one request every 1500 milliseconds from any given IP
thread::sleep(time::Duration::from_millis(1600));
}
} else {
api::acc_breach_request(data_search, &api_key);
api::acc_breach_request(data_search, &config.api_key);
}
}

Expand Down

0 comments on commit c5944fe

Please sign in to comment.