pwdbox

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2023 License: LGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PlatformMapperXml []byte

var uri string = "file:D:\\eclipse\\2022-06-R\\workspace\\pwdbox.db3"

View Source
var SqliteInited bool = false // 数据库是否初始化成功

Functions

func Decrypt

func Decrypt(ciphertext []byte, key []byte, iv []byte) ([]byte, error)

解密

func DecryptToString

func DecryptToString(ciphertext string, key []byte, iv []byte) (string, error)

func Encrypt

func Encrypt(plaintext []byte, key []byte, iv []byte) ([]byte, error)

加密 AES-128-CBC

func EncryptToString

func EncryptToString(plaintext string, key []byte, iv []byte) (string, error)

func GenID

func GenID() int64

生成 64 位的 雪花 ID

func InitSnowFlakeId

func InitSnowFlakeId(startTime string, machineID int64) (err error)

func InitSqlite

func InitSqlite(uri string)

初始化数据库链接

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

填充

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

去除填充

func TestAES

func TestAES()

Types

type Account

type Account struct {
	Id         int64  `json:"id"`
	PlatformId int64  `json:"platform_id"` // 平台
	Username   string `json:"username"`    // 用户名
	Password   string `json:"password"`    // 密码
	Phone      string `json:"phone"`       // 绑定电话(多个,隔开)
	Email      string `json:"email"`       // 绑定邮箱(多个,隔开)
	Remark     string `json:"remark"`      // 备注
	CreateTime string `json:"create_time"` // 创建时间
}

账户实体

type AccountMapper

type AccountMapper struct {
	Get    func(id int64) (Account, error) `args:"id"`
	Update func(p Account) error
	Save   func(p Account) error
	Delete func(id int64) error `args:"id"`
	// MaxNum func() (int, error)                                                              // maybe nil
	Count func(platformId int64, username string, phone string, email string) (int, error) `args:"platform_id,username,phone,email"`
	List  func(platformId int64, username string, phone string, email string,
		start int, offset int) ([]Account, error) `args:"platform_id,username,phone,email,start,offset"`
}

type AccountService

type AccountService struct {
	IsCreated bool // 是否初始化完成(链接数据库)
}
var AccountServiceInstance AccountService

用单例吧

func GetAccountService

func GetAccountService() AccountService

获取 AccountService,需要先初始化数据库链接

func (*AccountService) Delete

func (as *AccountService) Delete(id int64)

func (*AccountService) Get

func (as *AccountService) Get(id int64) Account

func (*AccountService) Init

func (as *AccountService) Init(sqlEngine GoMybatis.GoMybatisEngine)

func (*AccountService) List

func (as *AccountService) List(platformId int64, username string, phone string, email string,
	page int, size int) []Account

func (*AccountService) PageList

func (as *AccountService) PageList(platformId int64, username string, phone string, email string,
	page int, size int) PageData[Account]

func (*AccountService) Save

func (as *AccountService) Save(entity Account) *Account

func (*AccountService) Update

func (as *AccountService) Update(entity Account) Account

func (*AccountService) UpdatePwd

func (as *AccountService) UpdatePwd(id int64, newPassword string) bool

type AesInfo

type AesInfo struct {
	Key []byte
	IV  []byte
}

辅助保存 Key 和 iv 的类

var AesHolder AesInfo

持有并验证用户输入的 key 和 iv 是否正确

func NewAesInfo

func NewAesInfo(key string, iv string) AesInfo

type DbOp

type DbOp struct {
}

接口操作

func (*DbOp) IsInited

func (do *DbOp) IsInited() bool

Platform 的service

type EntityType

type EntityType interface {
	Account | Platform
}

type PageData

type PageData[T EntityType] struct {
	Page  int
	Size  int
	Total int
	Data  []T
}

func EmptyPageData

func EmptyPageData[T EntityType]() PageData[T]

func NewPageData

func NewPageData[T EntityType](page int, size int, total int, list []T) PageData[T]

type Platform

type Platform struct {
	Id     int64  `json:"id"`
	Name   string `json:"name"`   // 平台名称
	Site   string `json:"site"`   // 官网
	Remark string `json:"remark"` // 备注
	Num    int    `json:"num"`    // 序号
	// CreateTime time.Time `json:"create_time"` // 创建时间
	CreateTime string `json:"create_time"` // 创建时间
	Img        string `json:"img"`         // 图片
}

平台实体

type PlatformMapper

type PlatformMapper struct {
	Get    func(id int64) (Platform, error) `args:"id"`
	Update func(p Platform) error
	Save   func(p Platform) error
	Delete func(id int64) error                                         `args:"id"`
	MaxNum func() (int, error)                                          // maybe nil
	Count  func(name string) (int, error)                               `args:"name"`
	List   func(name string, start int, offset int) ([]Platform, error) `args:"name,start,offset"`
}
var PlatformMapperInstance PlatformMapper

type PlatformService

type PlatformService struct {
	IsCreated bool // 是否初始化完成(链接数据库)
}
var PlatformServiceInstance PlatformService

用单例吧

func GetPlatformService

func GetPlatformService() PlatformService

获取 PlatformService,需要先初始化数据库链接

func (*PlatformService) Delete

func (ps *PlatformService) Delete(id int64)

func (*PlatformService) Get

func (ps *PlatformService) Get(id int64) Platform

func (*PlatformService) Init

func (ps *PlatformService) Init(sqlEngine GoMybatis.GoMybatisEngine)

func (*PlatformService) List

func (ps *PlatformService) List(name string, page int, size int) []Platform

func (*PlatformService) PageList

func (ps *PlatformService) PageList(name string, page int, size int) PageData[Platform]

func (*PlatformService) Save

func (ps *PlatformService) Save(entity Platform) Platform

func (*PlatformService) Update

func (ps *PlatformService) Update(entity Platform) Platform

type PwdTool

type PwdTool struct {
}

加密解密工具类

func (*PwdTool) DecryptPwd

func (pt *PwdTool) DecryptPwd(encPwd string) string

解密方法

func (*PwdTool) ExistVerifyData

func (pt *PwdTool) ExistVerifyData() bool

检查是否存在验证数据

func (*PwdTool) GetAesInfo

func (pt *PwdTool) GetAesInfo() AesInfo

该方法只是为了让 js 中有 AesInfo 这个类型

func (*PwdTool) SaveAesInfo

func (pt *PwdTool) SaveAesInfo(key string, iv string) bool

保存验证数据

func (*PwdTool) VerifyAndKeepAesInfo

func (pt *PwdTool) VerifyAndKeepAesInfo(key string, iv string) (bool, error)

读取验证文件,然后验证 key 和 iv 是否正确

type Service

type Service interface {
	Init(sqlEngine GoMybatis.GoMybatisEngine) // 初始化
}

Jump to

Keyboard shortcuts

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