Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Count characters in password example instead of bytes #276

Merged
merged 2 commits into from Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/password.rs
Expand Up @@ -5,7 +5,7 @@ fn main() {
.with_prompt("Password")
.with_confirmation("Repeat password", "Error: the passwords don't match.")
.validate_with(|input: &String| -> Result<(), &str> {
if input.len() > 3 {
if input.chars().count() > 3 {
Ok(())
} else {
Err("Password must be longer than 3")
Expand All @@ -14,5 +14,8 @@ fn main() {
.interact()
.unwrap();

println!("Your password is {} characters long", password.len());
println!(
"Your password is {} characters long",
password.chars().count()
);
}
4 changes: 2 additions & 2 deletions src/prompts/password.rs
Expand Up @@ -86,7 +86,7 @@ impl Password<'_> {

/// Enables user interaction and returns the result.
///
/// If the user confirms the result is `true`, `false` otherwise.
/// If the user confirms the result is `Ok()`, `Err()` otherwise.
/// The dialog is rendered on stderr.
pub fn interact(self) -> Result<String> {
self.interact_on(&Term::stderr())
Expand Down Expand Up @@ -159,7 +159,7 @@ impl<'a> Password<'a> {
/// let password: String = Password::new()
/// .with_prompt("Enter password")
/// .validate_with(|input: &String| -> Result<(), &str> {
/// if input.len() > 8 {
/// if input.chars().count() > 8 {
/// Ok(())
/// } else {
/// Err("Password must be longer than 8")
Expand Down