-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
237393e
commit 18e7b00
Showing
3 changed files
with
53 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"syscall" | ||
|
||
"golang.org/x/term" | ||
) | ||
|
||
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() | ||
|
||
password := string(passwordBytes) | ||
validatePassword(password) | ||
|
||
fmt.Print("Confirm password: ") | ||
passwordConfirmationBytes, 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() | ||
|
||
passwordConfirmation := string(passwordConfirmationBytes) | ||
if password != passwordConfirmation { | ||
fmt.Fprintf(os.Stderr, "Passwords do not match.\n") | ||
os.Exit(1) | ||
} | ||
|
||
return password | ||
} | ||
|
||
func validatePassword(password string) { | ||
if len(password) < 8 { | ||
fmt.Fprintf(os.Stderr, "The password must be at least 8 characters long.\n") | ||
os.Exit(1) | ||
} | ||
} |