totp

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const TOTP = "totp"

Variables

View Source
var Index = &ice.Context{Name: "totp", Help: "动态码",
	Caches: map[string]*ice.Cache{},
	Configs: map[string]*ice.Config{
		TOTP: {Name: "totp", Help: "动态码", Value: kit.Data(
			kit.MDB_SHORT, "name", "share", "otpauth://totp/%s?secret=%s",
		)},
	},
	Commands: map[string]*ice.Command{
		ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
		ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},

		"new": {Name: "new user [secret]", Help: "创建密钥", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
			if len(arg) == 0 {

				m.Richs("totp", nil, "*", func(key string, value map[string]interface{}) {
					m.Push(key, value, []string{"time", "name"})
				})
				return
			}

			if m.Richs("totp", nil, arg[0], func(key string, value map[string]interface{}) {

				if len(arg) > 1 {
					m.Render(ice.RENDER_QRCODE, kit.Format(m.Conf("totp", "meta.share"), value["name"], value["text"]))
				} else {
					m.Push("detail", value)
				}
			}) != nil {
				return
			}

			if len(arg) == 1 {

				arg = append(arg, _totp_gen(30))
			}

			m.Log(ice.LOG_CREATE, "%s: %s", arg[0], m.Rich("totp", nil, kit.Dict(
				kit.MDB_NAME, arg[0], kit.MDB_TEXT, arg[1], kit.MDB_EXTRA, kit.Dict(arg[2:]),
			)))
		}},
		"get": {Name: "get [name [number [period]]] auto", Help: "获取密码", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
			if len(arg) == 0 {

				m.Richs("totp", nil, "*", func(key string, value map[string]interface{}) {
					per := kit.Int64(kit.Select("30", value["period"]))
					m.Push("time", m.Time())
					m.Push("rest", per-time.Now().Unix()%per)
					m.Push("name", value["name"])
					m.Push("code", _totp_get(kit.Format(value["text"]), kit.Int(kit.Select("6", value["number"])), per))

				})
				return
			}

			m.Richs("totp", nil, arg[0], func(key string, value map[string]interface{}) {

				m.Echo(_totp_get(kit.Format(value["text"]), kit.Int(kit.Select("6", arg, 1)), kit.Int64(kit.Select("30", arg, 2))))
			})
		}},
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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