From a00d1f317835211ef25828da29a2c996c6b10c71 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Sat, 25 Jan 2025 21:49:17 +0000 Subject: [PATCH] 0.1.2 adds PIN generation --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 4 +++- src/lib.rs | 14 +++++++++++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50e25a1..6871531 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -16,7 +16,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "division_of_one" -version = "0.1.0" +version = "0.1.2" dependencies = [ "rand", ] diff --git a/Cargo.toml b/Cargo.toml index 641bfe3..49c3693 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["passphrase", "password"] license = "AGPL-3.0" name = "division_of_one" repository = "https://six-five-six-four.com/git/reactor/division_of_one" -version = "0.1.1" +version = "0.1.2" [dependencies] rand = "0.8.5" diff --git a/README.md b/README.md index 28dd7bf..fc69d5b 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@ A diceware passphrase generator, e.g. `correct horse battery staple` +Also generates PINs. + Install with `cargo install division_of_one` or download the Windows exe from my Git forge: https://six-five-six-four.com/git/reactor/division_of_one # Why this and not another generator? -It's easier to write 40 lines of Rust than to audit it. +It's easier to write 50 lines of Rust than to audit it. I want to just point my friends and family at this without having to check if it's been compromised since the last time I saw it. diff --git a/src/lib.rs b/src/lib.rs index ce9d679..3f1673f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,10 @@ -use rand::seq::SliceRandom as _; +use rand::{seq::SliceRandom as _, Rng as _}; pub fn main() { let passphrase = create_passphrase(" ", 8); println!("{passphrase}"); + let pin = create_pin(8); + println!("{pin}"); println!("Press Enter"); let mut input = String::new(); std::io::stdin().read_line(&mut input).ok(); @@ -14,6 +16,16 @@ pub fn create_passphrase(separator: &str, len: usize) -> String { words.join(separator) } +/// Generates a decimal PIN +/// +/// PINs are returned as a String because you do not do math with PINs, therefore they are not numbers. +pub fn create_pin(len: usize) -> String { + let digits: Vec<_> = (0..len) + .map(|_| format!("{}", rand::thread_rng().gen_range(0..=9))) + .collect(); + digits.join("") +} + pub struct Dice { words: Vec, }