Beispiel #1
0
func ExamplePassword() {
	passwd := prompter.Password("Enter your password")
	_ = passwd
	fmt.Println("****")
	fmt.Print("I got your password! :P")
	// Output:
	// Enter your password: ****
	// I got your password! :P
}
Beispiel #2
0
// CreateUser is a procedure for creating a user
func CreateUser(cmd *cobra.Command, args []string) {
	database.InitDB()
	db := database.GetDB()

	username := viper.GetString("name")
	if username == "" {
		fmt.Println("Required 'name' parameter not specified")
		return
	}

	fmt.Printf("Creating User %s...\n", username)

	for _, item := range db.Users {
		if item.Username == username {
			logrus.Errorf("User %s already exists in the database", username)
			return
		}
	}

	// Generate TOTP
	init2FA, err := gototp.New(gototp.RandomSecret(10))
	if err != nil {
		logrus.Error(err)
		return
	}

	// check if password was specified, otherwise, go interactive
	password := viper.GetString("password")
	if password == "" {
		password = prompter.Password("Enter password to use")
	}

	user, err := pwMan.NewUser(username, password, init2FA.Secret())
	if err != nil {
		fmt.Printf("Error while creating user %s: %v\n", username, err)
	}

	db.AddUser(*user)

	fmt.Printf("User %s created. Caracteristics :\n", username)
	fmt.Printf("2FA init: %s || QRCode link: %s\n", init2FA.Secret(), init2FA.QRCodeGoogleChartsUrl("Code", 320))
	//fmt.Println(.QRCodeTerminal("label"))

}
Beispiel #3
0
func main() {
	input := (&prompter.Prompter{
		Choices:    []string{"aa", "bb", "cc"},
		Default:    "aa",
		Message:    "plaase select",
		IgnoreCase: true,
	}).Prompt()
	fmt.Println("your input is " + input)

	input = (&prompter.Prompter{
		Message: "enter password",
		Regexp:  regexp.MustCompile(`.{8,}`),
		NoEcho:  true,
	}).Prompt()
	fmt.Println("your password is " + input)

	if prompter.YN("do you like sushi?", true) {
		fmt.Println("Nice!")
	} else {
		fmt.Println("It's Okay.")
	}

	if prompter.YesNo("do you like beer?", false) {
		fmt.Println("Nice!")
	} else {
		fmt.Println("It's Okay.")
	}

	passwd := prompter.Password("enter your password")
	fmt.Println("I got your password :P " + passwd)

	lang := prompter.Choose("Whitch language do you like the most?", []string{"Perl", "Golang", "Scala", "Ruby"}, "Perl")
	if lang == "Perl" {
		fmt.Println("So Nice!")
	} else {
		fmt.Println("I like also " + lang + " too.")
	}
}