8 releases (4 breaking)

0.5.0 Apr 30, 2021
0.4.0 Dec 10, 2020
0.3.0 Nov 23, 2020
0.2.1 Jun 20, 2020
0.1.1 Mar 30, 2018

#2469 in Cryptography

Download history 1436/week @ 2025-10-27 1522/week @ 2025-11-03 1472/week @ 2025-11-10 1572/week @ 2025-11-17 1155/week @ 2025-11-24 1240/week @ 2025-12-01 1317/week @ 2025-12-08 932/week @ 2025-12-15 769/week @ 2025-12-22 729/week @ 2025-12-29 1087/week @ 2026-01-05 1118/week @ 2026-01-12 1243/week @ 2026-01-19 1613/week @ 2026-01-26 1502/week @ 2026-02-02 1615/week @ 2026-02-09

6,032 downloads per month

MIT/Apache

12KB
142 lines

Crates.io Build Status MIT licensed Apache-2.0 licensed

pwned-rs

Check your passwords against Have I been pwned?

Usage

Add this to your Cargo.toml

[dependencies]
pwned = { git = "https://github.com/wisespace-io/pwned-rs.git" }

Check a password against the API and see the number of occurrences

It uses the range API, so only the first 5 characters of a SHA1 hashed password are sent to Have I been pwned?

use pwned::api::*;

#[tokio::main]
async fn main() {
    let pwned = PwnedBuilder::default()
        .build().unwrap();

    match pwned.check_password("password").await {
        Ok(pwd) => println!("Pwned? {} - Occurrences {}", pwd.found, pwd.count),
        Err(e) => println!("Error: {}", e),
    }
}

Check all breaches for an account

use pwned::api::*;
#[tokio::main]
async fn main() {
    
    let pwned = PwnedBuilder::default()
        .user_agent("my_user_agent")
        .api_key(std::env::var("HIBP_API_KEY").expect("You need to give your HIBP API key as the HIBP_API_KEY environment variable"))
        .build().unwrap();

    match pwned.check_email("test@wisespace.io").await {
        Ok(answer) => {
            for breach in answer {
                println!("Service {:?}, breach date {:?} Domain: {:?}", breach.name, breach.breach_date, breach.domain);
            }
        },
        Err(e) => println!("Message: {}", e),
    }

}

Dependencies

~5–20MB
~231K SLoC