auth

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2022 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PasswordHashLength = 16
)

Variables

This section is empty.

Functions

func GenerateAuthCommandData

func GenerateAuthCommandData(user *HashUser) []byte

GenerateAuthCommandData generate auth command request data

func ParseStringUsers

func ParseStringUsers(users []*User) (userStr string, err error)

ParseStringUsers parse user list to user string

Types

type HashUser

type HashUser struct {
	// UserNameHash a 16 bytes hash of username
	UserNameHash string
	// PasswordHash a 16 bytes hash of password
	PasswordHash string
	// Expires 14 bytes auth request info expires of utc, format like "20060102150405"
	Expires string
	// Version 2 bytes of auth api version
	Version []byte
}

HashUser store the hash info of User

func NewHashUser

func NewHashUser(userNameHash, passwordHash string) *HashUser

func ParseAuthCommandData

func ParseAuthCommandData(data []byte) (user *HashUser, err error)

ParseAuthCommandData parse auth command request data

func ToHashUserList

func ToHashUserList(users []*User) (hashUsers []*HashUser, err error)

ToHashUserList convert User list to HashUser list

func (*HashUser) IsExpired

func (h *HashUser) IsExpired() bool

IsExpired auth request info is expired or not

func (*HashUser) RefreshExpires

func (h *HashUser) RefreshExpires() string

RefreshExpires refresh expires with current utc time

type SessionUser

type SessionUser struct {
	UserId   int
	UserName string
	Password string
}

func MapperToSessionUser

func MapperToSessionUser(user *User) *SessionUser

type User

type User struct {
	// contains filtered or unexported fields
}

User a login user info

func NewUser

func NewUser(userId int, userName string, password string) (*User, error)

NewUser create a new user

func ParseUsers

func ParseUsers(userStr string) (users []*User, err error)

ParseUsers parse users string to User List For example: user1|password1,user2|password2

func RandomUser

func RandomUser(count, userLen, pwdLen int) []*User

RandomUser generate some user with random username and password count is user count you want userLen is the length of random username, max length is 20 pwdLen is the length of random password, max length is 20

func (*User) Password

func (user *User) Password() string

func (*User) String

func (user *User) String() string

func (*User) ToHashUser

func (user *User) ToHashUser() (hashUser *HashUser, err error)

ToHashUser convert User to HashUser

func (*User) UserId

func (user *User) UserId() int

func (*User) UserName

func (user *User) UserName() string

Jump to

Keyboard shortcuts

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