Skip to content

Commit

Permalink
init (done): everything works as expected
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparkenstein committed Oct 12, 2020
0 parents commit c4526a1
Show file tree
Hide file tree
Showing 4 changed files with 254 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
184 changes: 184 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "passgen"
version = "0.1.0"
authors = ["Sparkenstein <[email protected]>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.7.3"
clap = "2.33.3"
58 changes: 58 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
extern crate clap;

use clap::{App, Arg};
use rand::{thread_rng, Rng};

fn main() {
let mut rng = thread_rng();
let matches = App::new("passgen")
.version("1.0")
.author("@Sparkenstein")
.about("Generate Random password on command line")
.arg(
Arg::with_name("include")
.long("include")
.short("i")
.default_value("nlus")
.help("include numbers/upppercase/lowercase/symbols in generated string"),
)
.arg(
Arg::with_name("length")
.long("length")
.short("l")
.takes_value(true)
.default_value("16")
.help("include lowercase characters in generated string"),
)
.get_matches();
let chars_to_include = matches.value_of("include").unwrap();
let mut pass_string = String::from("");
if chars_to_include.contains("l") {
pass_string += "abcdefghijklmnopqrstuvwxyz";
}

if chars_to_include.contains("n") {
pass_string += "0123456789";
}

if chars_to_include.contains("s") {
pass_string += ")(*&^%$#@!~";
}

if chars_to_include.contains("u") {
pass_string += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
}

let length = matches
.value_of("length")
.unwrap()
.parse::<usize>()
.unwrap();
let password = (0..length)
.map(|_| {
let idx = rng.gen_range(0, pass_string.len());
pass_string.chars().nth(idx).unwrap()
})
.collect::<String>();
println!("{}", password);
}

0 comments on commit c4526a1

Please sign in to comment.