mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-06 02:29:57 +02:00
Create utility for ensuring a password is set (with prompt)
This commit is contained in:
parent
2ee0ae0194
commit
804455e13d
4 changed files with 30 additions and 22 deletions
|
@ -93,3 +93,26 @@ pub fn prompt_password() -> String {
|
|||
)),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a password if required.
|
||||
/// This method will ensure a password is set (or not) in the given `password`
|
||||
/// parameter, as defined by `needs`.
|
||||
///
|
||||
/// This method will prompt the user for a password, if one is required but
|
||||
/// wasn't set. An ignore message will be shown if it was not required while it
|
||||
/// was set.
|
||||
pub fn ensure_password(password: &mut Option<String>, needs: bool) {
|
||||
// Return if we're fine
|
||||
if password.is_some() == needs {
|
||||
return;
|
||||
}
|
||||
|
||||
// Ask for a password, or reset it
|
||||
if needs {
|
||||
println!("This file is protected with a password.");
|
||||
*password = Some(prompt_password());
|
||||
} else {
|
||||
println!("Ignoring password, it is not required");
|
||||
*password = None;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue