Read password securely from Stdin
This commit is contained in:
parent
f1d4e0a8d5
commit
b9e7c03a28
2 changed files with 4 additions and 7 deletions
|
|
@ -6,25 +6,24 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/AYM1607/ccclip/internal/configfile"
|
"github.com/AYM1607/ccclip/internal/configfile"
|
||||||
|
"github.com/AYM1607/ccclip/pkg/input"
|
||||||
)
|
)
|
||||||
|
|
||||||
var email string
|
var email string
|
||||||
var password string
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(registerCmd)
|
rootCmd.AddCommand(registerCmd)
|
||||||
|
|
||||||
registerCmd.Flags().StringVarP(&email, "email", "e", "", "email will be your login identifier")
|
registerCmd.Flags().StringVarP(&email, "email", "e", "", "email will be your login identifier")
|
||||||
registerCmd.Flags().StringVarP(&password, "password", "p", "", "password will secure your account")
|
|
||||||
|
|
||||||
registerCmd.MarkFlagRequired("email")
|
registerCmd.MarkFlagRequired("email")
|
||||||
registerCmd.MarkFlagRequired("password")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var registerCmd = &cobra.Command{
|
var registerCmd = &cobra.Command{
|
||||||
Use: "register",
|
Use: "register",
|
||||||
Short: "Register a user with a given email and password",
|
Short: "Register a user with a given email and password",
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
password := input.ReadPassword()
|
||||||
err := apiclient.Register(email, password)
|
err := apiclient.Register(email, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not register user: %w", err)
|
return fmt.Errorf("could not register user: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,11 @@ import (
|
||||||
|
|
||||||
"github.com/AYM1607/ccclip/internal/configfile"
|
"github.com/AYM1607/ccclip/internal/configfile"
|
||||||
"github.com/AYM1607/ccclip/pkg/crypto"
|
"github.com/AYM1607/ccclip/pkg/crypto"
|
||||||
|
"github.com/AYM1607/ccclip/pkg/input"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(registerDeviceCommand)
|
rootCmd.AddCommand(registerDeviceCommand)
|
||||||
|
|
||||||
registerDeviceCommand.Flags().StringVarP(&password, "password", "p", "", "password for your account")
|
|
||||||
|
|
||||||
registerDeviceCommand.MarkFlagRequired("password")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var registerDeviceCommand = &cobra.Command{
|
var registerDeviceCommand = &cobra.Command{
|
||||||
|
|
@ -37,6 +34,7 @@ var registerDeviceCommand = &cobra.Command{
|
||||||
pvk := crypto.NewPrivateKey()
|
pvk := crypto.NewPrivateKey()
|
||||||
pbk := pvk.PublicKey()
|
pbk := pvk.PublicKey()
|
||||||
|
|
||||||
|
password := input.ReadPassword()
|
||||||
res, err := apiclient.RegisterDevice(cc.Email, password, pbk.Bytes())
|
res, err := apiclient.RegisterDevice(cc.Email, password, pbk.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue