Optimize empty password checking

This commit is contained in:
timvisee 2018-04-12 21:49:05 +02:00
parent 3cba92c494
commit 1099a80c79
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
3 changed files with 32 additions and 15 deletions

View file

@ -163,6 +163,23 @@ pub fn set_clipboard(content: String) -> Result<(), Box<StdError>> {
context.set_contents(content)
}
/// Check for an emtpy password in the given `password`.
/// If the password is emtpy the program will quit with an error unless
/// forced.
// TODO: move this to a better module
pub fn check_empty_password(password: &str, matcher_main: &MainMatcher) {
if !matcher_main.force() && password.is_empty() {
quit_error_msg(
"An empty password is not supported by the web interface",
ErrorHintsBuilder::default()
.force(true)
.verbose(false)
.build()
.unwrap(),
)
}
}
/// Prompt the user to enter a password.
///
/// If `empty` is `false`, emtpy passwords aren't allowed unless forced.