Skip to content

Commit

Permalink
cmd/microcloud: Allow multiple spaces between passphrase elements
Browse files Browse the repository at this point in the history
Prevents an accidental double-tap of the spacebar from rejecting the
entire passphrase.

Allows this: `a b  c d`

Signed-off-by: Wesley Hershberger <[email protected]>
  • Loading branch information
MggMuggins committed Dec 18, 2024
1 parent 33b2aad commit bbf626d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions cmd/microcloud/ask.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"net"
"slices"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -1485,14 +1486,17 @@ func (c *initConfig) shortFingerprint(fingerprint string) (string, error) {

func (c *initConfig) askPassphrase(s *service.Handler) (string, error) {
format := func(password string) (string, error) {
trimmed := strings.TrimSpace(password)
passwordSplit := strings.SplitN(trimmed, " ", 5)
passwordSplit := strings.Split(password, " ")

if len(passwordSplit) != 4 {
passwordClean := slices.DeleteFunc(passwordSplit, func(element string) bool {
return element == ""
})

if len(passwordClean) != 4 {
return "", fmt.Errorf("Passphrase has to contain exactly four elements")
}

return trimmed, nil
return strings.Join(passwordClean, " "), nil
}

validator := func(password string) error {
Expand Down

0 comments on commit bbf626d

Please sign in to comment.