Skip to content

Commit

Permalink
allow empty password (console-rs#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDP authored and mitsuhiko committed Nov 25, 2018
1 parent d03a7a5 commit 20ecb93
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/prompts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub struct Input<'a, T> {
pub struct PasswordInput<'a> {
prompt: String,
theme: &'a Theme,
allow_empty_password: bool,
confirmation_prompt: Option<(String, String)>,
}

Expand Down Expand Up @@ -246,6 +247,7 @@ impl<'a> PasswordInput<'a> {
PasswordInput {
prompt: "".into(),
theme: theme,
allow_empty_password: false,
confirmation_prompt: None,
}
}
Expand All @@ -266,6 +268,14 @@ impl<'a> PasswordInput<'a> {
self
}

/// Allows/Disables empty password.
///
/// By default this setting is set to false (i.e. password is not empty).
pub fn allow_empty_password(&mut self, allow_empty_password: bool) -> &mut PasswordInput<'a> {
self.allow_empty_password = allow_empty_password;
self
}

/// Enables user interaction and returns the result.
///
/// If the user confirms the result is `true`, `false` otherwise.
Expand Down Expand Up @@ -301,7 +311,7 @@ impl<'a> PasswordInput<'a> {
render.password_prompt(prompt)?;
let input = render.term().read_secure_line()?;
render.add_line();
if !input.is_empty() {
if !input.is_empty() || self.allow_empty_password {
return Ok(input);
}
}
Expand Down

0 comments on commit 20ecb93

Please sign in to comment.