Skip to content

Commit

Permalink
Don't prompt for password verification on decrypt
Browse files Browse the repository at this point in the history
  • Loading branch information
angelsolaorbaiceta committed Sep 9, 2024
1 parent dcdcfa6 commit 83200d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/aar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func main() {
case "encrypt":
encryptCmd.Parse(os.Args[2:])
validateFileName(*encryptFileNameFlag)
password := cmd.PromptPassword()
password := cmd.PromptPasswordWithConfirmation()

cmd.EncryptArchive(*encryptFileNameFlag, password)

Expand Down
16 changes: 15 additions & 1 deletion cmd/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"golang.org/x/term"
)

func PromptPassword() string {
func PromptPasswordWithConfirmation() string {
fmt.Print("Password: ")
passwordBytes, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
Expand Down Expand Up @@ -41,6 +41,20 @@ func PromptPassword() string {
return password
}

func PromptPassword() string {
fmt.Print("Password: ")
passwordBytes, err := term.ReadPassword(int(syscall.Stdin))
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading password: %v\n", err)
os.Exit(1)
}

// Move to the next line after password input
fmt.Println()

return string(passwordBytes)
}

func validatePassword(password string) {
if len(password) < 8 {
fmt.Fprintf(os.Stderr, "The password must be at least 8 characters long.\n")
Expand Down

0 comments on commit 83200d1

Please sign in to comment.