cmds

package
v0.0.0-...-b755440 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2019 License: GPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Source = []string{
		"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
		"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z",
		"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
	}

	Special = []string{
		`!`, `@`, `#`, `$`, `%`, `&`, `*`, `-`, `+`, `=`, `?`, `<`, `>`, `[`, `]`, "{", "}",
	}

	WithSpec     bool
	Security     int
	SecurityUnit int
	Desc         string
)
View Source
var GenerCmd = &cobra.Command{
	Use:   "gen",
	Short: "Generate New Password",
	Args: func(cmd *cobra.Command, args []string) error {
		unit := func() int {
			if WithSpec {
				return 4

			} else {
				return 3
			}
		}

		if SecurityUnit*unit() > Security {
			return errors.New("unit exceed security")
		}

		return nil
	},

	Run: func(cmd *cobra.Command, args []string) {
		if WithSpec {
			Source = append(Source, Special...)
		}

		var pwd []byte
		for pwd == nil {
			pwd = generatePwd(Security, SecurityUnit, WithSpec)
		}

		encPwd, err := util.ScanEncPwd(true)
		if err != nil {
			return
		}

		keyName, err := crypto.Encrypt(encPwd, pwd, Desc)
		if err != nil {
			return
		}

		fmt.Println(fmt.Sprintf("\nThe password is saved in the %s file.", keyName))
	},
}
View Source
var (
	Key string
)
View Source
var ReaderCmd = &cobra.Command{
	Use:   "read",
	Short: "Read Encrypted Password",
	Run: func(cmd *cobra.Command, args []string) {
		payload, err := ioutil.ReadFile(Key)
		if err != nil {
			logger.Error(err)
			return
		}

		pwd, err := util.ScanEncPwd(false)
		if err != nil {
			return
		}

		raw, err := crypto.Decrypt(pwd, payload)
		if err != nil {
			return
		}

		fmt.Print(string(raw))
	},
}

Functions

func Shuffle

func Shuffle(source []string, thousands int) []string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL