Skip to content

Commit

Permalink
Add an option to output only one password.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkulak committed Jun 8, 2020
1 parent 7ba3644 commit 3783982
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
PGen
====

This is a very opinionated password generator. It takes only one option (length), and generates 5 passwords:
This is a very opinionated password generator. It can generate five types of password, in increasing complexity, and otherwise only takes length as an option.

phil@fry ~> pgen
dyrumiwusy zbamsyztet qMBkkmjRPb dMazV2mKWm h1c3AceR9.

The first is (mostly, sometimes) pronounceable, the second is all lower case, the third is upper and lower case, the fourth includes digits, and the last adds a sigle special character. The idea is to pick the right password based on the specific security/convenience tradeoffs of where it's being used, or the silly and misguided requirements of the application.

Options
=======

-**l** or --**length**: How long should the password be? Defaults to 10.

-**c** or --**complexity**: Print out a single password only. Values are from 1 to 5, inclusive. Defaults to not set (or 0).

FAQ
===

Expand All @@ -17,5 +24,8 @@ I'm really trying to get familiar with Rust, so I'm forcing myself to use it.
**Why can't I configure the passwords I see and how they are built?**
Yeah, that's a good idea. That's probably the next step.

**Some of this code is really not how you're supposed to write Rust...**
Please let me know! This is my first project, and I'd love to know what mistakes I'm making. PRs welcome, of course, or just yell at me.

**Can you really have FAQs if no one has ever asked anything?**
Apparently.
22 changes: 21 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,33 @@ mod pronounce;
#[clap(version = "1.0", author = "Phil K.")]
struct Opts {
#[clap(short = "l", long = "length", default_value = "10", help = "The length of each password")]
length: u32
length: u32,

#[clap(short = "c", long = "complexity", default_value="0")]
complexity: usize
}

fn main() {
let opts: Opts = Opts::parse();
let all = vec![lower_class(), upper_class(), number_class(), symbol_class()];

let complexity = if opts.complexity > 5 {
5
} else {
opts.complexity
};

if complexity > 0 {
let pass = if complexity == 1 {
pronounce::generate_password(make_default_graph(), opts.length)
} else {
password::generate_password(&all[0..complexity - 1], opts.length)
};

println!("{}", pass);
return
}

println!("{}\t{}\t{}\t{}\t{}",
pronounce::generate_password(make_default_graph(), opts.length),
password::generate_password(&all[0..1], opts.length),
Expand Down

0 comments on commit 3783982

Please sign in to comment.