passphrase_lib/lib.rs
1//! Passhrase is a pure Rust library focused on generating solid passphrases at the touch of a button
2//! , giving users the ability to generate memorable strong passphrases that takes thousands of
3//! years to crack using specialized password cracking computers or taking forever for normal
4//! computers to crack.
5//!
6//!At the moment(an English only version is coming soon),
7//! it combines English and Swahili dictionaries of short easy to type words.
8//! The `zxcvbn` crate, a password strength estimator based off of Dropbox's zxcvbn library,
9//!has been used to counter-check how long it would take to crack the password,
10//!the number of guesses it would need and the number of years it would take to crack the passphrase.
11//!
12//! However, kindly node that this is only a passphrase generator and you need to hash it with
13//! a good hashing algorithm (I recommend argon2 implementations) for use to store in a database
14//!
15//! [WARNING!!!] NEVER STORE THE PLAIN TEXT VERSION OF A PASSPHRASE
16//!
17//! ---
18
19//! use `cargo add passphrase` to install to add to your `Cargo.toml` file.
20
21//! To add it manually to `Cargo.toml` file.
22//! ```
23//! [dependencies]
24//! passhrase_lib = #enter the version from crates.io here
25//! ```
26//! ---
27//! Usage:
28//! ```
29//! use passhrase;
30//! fn main() {
31//! // Generate a random passphrase
32//! let random_number = passphrase_lib::gen_passphrase();
33//!
34//! //Generate a random url
35//! let random_url = passphrase_lib::gen_url();
36//! }
37//! ```
38//!
39//! ---
40#![forbid(unsafe_code)]
41mod dictionary;
42
43use crate::dictionary::*;
44use nanorand::{RNG, ChaCha};
45
46fn choose_a_word(data_type: &'static[&'static str]) -> &str {
47 let size = data_type.len();
48 let data_type = data_type[ChaCha::new(32).generate_range(0, size)];
49 data_type
50}
51
52pub fn gen_passphrase() -> String {
53 let first_iteration = SWAHILI;
54 let second_iteration = ENGLISH;
55 let third_iteration = SWAHILI;
56 let fourth_iteration = ENGLISH;
57
58 let passphr = format!("{} {} {} {}", choose_a_word(second_iteration), choose_a_word(first_iteration), choose_a_word(fourth_iteration), choose_a_word(third_iteration));
59
60 passphr
61
62}
63
64pub fn gen_url() -> String {
65 let first_iteration = SWAHILI;
66 let second_iteration = ENGLISH;
67 let fourth_iteration = ENGLISH;
68
69 let passphr = format!("{}-{}-{}", choose_a_word(second_iteration), choose_a_word(first_iteration), choose_a_word(fourth_iteration));
70
71 passphr
72}
73
74pub fn english() -> String {
75
76 let passphr = format!("{}-{}-{}", choose_a_word(ENGLISH), choose_a_word(ENGLISH), choose_a_word(ENGLISH));
77
78 passphr
79}