aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-03-03 17:33:23 +0100
committerTeddy Wing2018-03-03 17:33:23 +0100
commit99fa6cb2210328c8a7ba96e56971788aac5bce27 (patch)
tree7c1cbbceacc8f398f5c790869f18731e7ffda553
parent9faef460fa13857ca26b4447b9d627bb76e9bbd9 (diff)
downloadPassextract-99fa6cb2210328c8a7ba96e56971788aac5bce27.tar.bz2
When `-i`, replace password with '*'s
Previously, when the "invisible" flag was activated, we wouldn't print anything except the "p: " prefix on a password line. This made it difficult to verify the password, and if you for some reason had multiple passwords, you wouldn't know which one to pick unless you knew the order. This at least gives you a visual cue about your password.
-rw-r--r--src/main.rs16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 7411c1a..28b0259 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -89,6 +89,20 @@ fn is_password_line(line: &str) -> bool {
line.starts_with("p: ")
}
+/// Replaces the password on a password line with "*"s.
+///
+/// # Examples
+///
+/// ```
+/// assert_eq!(hide_password_line("p: secret"), "p: ******);
+/// ```
+fn hide_password_line(line: &str) -> String {
+ const KEY_LENGTH: usize = 3;
+ let password_length = line.len() - KEY_LENGTH;
+
+ format!("p: {}", "*".repeat(password_length))
+}
+
fn main() {
let args: Vec<String> = env::args().collect();
@@ -132,7 +146,7 @@ fn main() {
for (i, s) in options.iter().enumerate() {
if hide_password && is_password_line(s) {
- term.printline(5, i + 2, "p: ")
+ term.printline(5, i + 2, &hide_password_line(s))
} else {
term.printline(5, i + 2, s)
}