Skip to content

Commit

Permalink
Merge pull request #6 from omekina/dev
Browse files Browse the repository at this point in the history
Hide password input
  • Loading branch information
omekina authored Nov 26, 2023
2 parents 2e35e76 + 7ac42e2 commit e27efa6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ edition = "2021"
[dependencies]
base64 = "0.21.5"
native-tls = "0.2.11"
rpassword = "7.3"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ smail init
This will guide us through config file creation. If you wish you can change it manually.
The config file should be located in `~/.smailconf`.

The `smail init` command will openly prompt for your password and the password will
The `smail init` command will prompt for your password and the password will
be written in plaintext into the config file. So please keep that in mind.

### 2. Create a test mail
Expand Down
6 changes: 5 additions & 1 deletion src/config/maker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ pub fn init(filepath: &String, arguments: &Vec<String>) -> bool {

// Get information from user
let user_input = match io::input::read_items(
vec!["SMTP server hostname", "Your username", "Your password"]
vec![
io::input::InputItem::Normal("SMTP server hostname"),
io::input::InputItem::Normal("Your username"),
io::input::InputItem::Hidden("Your password"),
]
) {
Some(value) => value,
None => {
Expand Down
37 changes: 31 additions & 6 deletions src/io/input.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,41 @@
extern crate rpassword;


use rpassword::read_password;
use std::io::{stdin, stdout, Write};

pub fn read_items(prompts: Vec<&str>) -> Option<Vec<String>> {

/**
Input item for command line inputs with prompts.
*/
pub enum InputItem {
Normal(&'static str),
Hidden(&'static str),
}


/**
Read specified items to the command line.
*/
pub fn read_items(prompts: Vec<InputItem>) -> Option<Vec<String>> {
let mut result = Vec::new();
for prompt in prompts {

for current_input in prompts {
let mut line = String::new();
print!("{}: ", prompt);

print!("{}: ", match current_input {
InputItem::Normal(value) => value,
InputItem::Hidden(value) => value,
});
stdout().flush().unwrap();
match stdin().read_line(&mut line) {
Ok(_) => {},
Err(_) => return None,

match current_input {
InputItem::Normal(_) => { let _ = stdin().read_line(&mut line).ok()?; },
InputItem::Hidden(_) => line = read_password().ok()?,
};

result.push(line);
}

return Some(result);
}

0 comments on commit e27efa6

Please sign in to comment.