Skip to content

Commit

Permalink
More idiomatic construction
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronFeickert committed Jan 13, 2023
1 parent b419bfc commit 81704dc
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions applications/tari_console_wallet/src/init/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use tari_wallet::{
WalletConfig,
WalletSqlite,
};
use zxcvbn::{feedback::Suggestion, zxcvbn};
use zxcvbn::zxcvbn;

use crate::{
cli::Cli,
Expand All @@ -79,19 +79,13 @@ pub enum WalletBoot {
}

/// Get feedback, if available, for a weak passphrase
fn get_password_feedback(passphrase: &SafePassword) -> Option<Vec<Suggestion>> {
if let Ok(passphrase_str) = std::str::from_utf8(passphrase.reveal()) {
match zxcvbn(passphrase_str, &[]) {
Ok(scoring) => scoring
.feedback()
.to_owned()
.map(|feedback| feedback.suggestions().to_owned()),
_ => None,
}
} else {
// Fail empty if we can't convert the passphrase back to a string, which shouldn't happen
None
}
fn get_password_feedback(passphrase: &SafePassword) -> Option<Vec<String>> {
std::str::from_utf8(passphrase.reveal())
.ok()
.and_then(|passphrase| zxcvbn(passphrase, &[]).ok())
.and_then(|scored| scored.feedback().to_owned())
.map(|feedback| feedback.suggestions().to_owned())
.map(|suggestion| suggestion.into_iter().map(|item| item.to_string()).collect())
}

// Display password feedback to the user
Expand Down

0 comments on commit 81704dc

Please sign in to comment.