-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init (done): everything works as expected
- Loading branch information
0 parents
commit c4526a1
Showing
4 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |