rs_password_utils/
lib.rs

1// Copyright 2020 astonbitecode
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*!
16# rs-password-utils
17
18![pipeline](https://gitlab.com/astonbitecode/rs-password-utils/badges/master/pipeline.svg)
19
20This library contains password utilities and is written in [Rust](https://www.rust-lang.org/).
21
22Currently it offers:
23
24* Checking passwords against [pwned passwords list](https://www.troyhunt.com/ive-just-launched-pwned-passwords-version-2/).
25
26The check implementation leverages the [k-anonimity API](https://blog.cloudflare.com/validating-leaked-passwords-with-k-anonymity/) and therefore, the password is not used in the API calls in any form (not even hashed).
27
28* [Diceware](https://theworld.com/~reinhold/diceware.html) for generating passphrases
29
30## Usage
31
32The utility can be used as a library, or as an executable:
33
34### Library
35
36```rust
37extern crate rs_password_utils;
38use std::result::Result;
39
40#[tokio::main]
41async fn main() -> Result<(), rs_password_utils::PasswordUtilsError> {
42    let is_pwned = rs_password_utils::pwned::is_pwned("test").await?;
43
44    println!("The password is pwned: {}", is_pwned);
45
46    Ok(())
47}
48```
49
50### Executable
51
52Having rust [installed](https://www.rust-lang.org/tools/install), you may install rs-password-utils using cargo:
53
54* From crates.io:
55`cargo install rs-password-utils --features executable`
56
57* From gitlab:
58`cargo install --git https://gitlab.com/astonbitecode/rs-password-utils.git --features executable`
59
60When the installation completes, issuing the following command:
61
62`rs-password-utils --help`
63
64should give you an output like:
65
66```bash
67Password utilities, written in Rust.
68
69 Usage:
70   rs-password-utils pwned
71   rs-password-utils dice [(-w <count>)]
72   rs-password-utils [-h]
73
74 Options:
75   -w --words    The amount of words that should comprise the passphrase
76   -h --help     Show this screen.
77```
78
79## License
80
81At your option, under:
82
83* Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0)
84* MIT license (http://opensource.org/licenses/MIT)
85*/
86
87extern crate hyper;
88extern crate futures;
89extern crate tokio;
90extern crate hyper_tls;
91extern crate sha1;
92extern crate hex;
93extern crate rand;
94
95pub mod pwned;
96pub mod dice;
97mod errors;
98pub use errors::PasswordUtilsError;