authentication

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

README

authentication

golang package authentication

example usage package to authentication_test.go

  • Registration
  • Authentication
  • ForgotPassword and RecoveryPassword
  • ChangeEmail
  • ChangePassword
  • PublicToken
  • DeleteProfile
PASS
coverage: 85.3% of statements
ok      github.com/v-grabko1999/authentication  0.429s

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenInvalidSignature = errors.New("token invalid digital signature")
	ErrWrongLoginOrPassword  = errors.New("wrong login or password")
	ErrWrongPassword         = errors.New("wrong password")

	ErrLoginNotUnique = errors.New("login is not unique")
	ErrEmailNotUnique = errors.New("email is not unique")

	ErrEmailSecretKeyNotFound = errors.New("email secret key not found")
	ErrTokenNotFound          = errors.New("token not found")
	ErrTokenGoneLifeTime      = errors.New("token lifetime is gone")
	ErrLoginNotFound          = errors.New("login not found")
	ErrEmailNotFound          = errors.New("login not found")
	ErrProfileIdNotFound      = errors.New("profile id not found")
)

Functions

This section is empty.

Types

type Auth

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

func NewAuth

func NewAuth(cfg AuthConfig) *Auth

func (*Auth) AllowedChangeEmail

func (a *Auth) AllowedChangeEmail(key EmailSecretKey, newEmail string) error

func (*Auth) Authentication

func (a *Auth) Authentication(login, password string) (*Profile, error)

func (*Auth) DelPublicToken

func (a *Auth) DelPublicToken(publickToken string, profID ProfileID) error

func (*Auth) ForgotPassword

func (a *Auth) ForgotPassword(email string) (EmailSecretKey, error)

func (*Auth) NewToken

func (a *Auth) NewToken(prof *Profile, tokenLifeTimeSecond TokenLifeTime) (string, error)

func (*Auth) ReadToken

func (a *Auth) ReadToken(publickToken string) (*Profile, error)

func (*Auth) RecoveryPassword

func (a *Auth) RecoveryPassword(key EmailSecretKey, newPassword string) error

func (*Auth) Registration

func (a *Auth) Registration(login, email, password string) (*Profile, error)

type AuthConfig

type AuthConfig struct {
	DriverStorage       DriverStorage
	EmailLifeTimeSecond int64
	ProfilePasswordSalt []byte
	TokenSecretKey      []byte
}

type DriverStorage

type DriverStorage interface {
	//EmailReadSecretKey должен возвращать такие стандартные ошибки:
	//authentication.ErrEmailSecretKeyNotFound - если записи с таким ключом в базе не найдено
	//authentication.ErrEmailSecretKeyNotFound - если время жизни токена истекло
	EmailReadSecretKey(key EmailSecretKey) (email string, err error)

	//EmailReadSecretKey должен возвращать такие стандартные ошибки:
	//authentication.ErrTokenNotFound - время жизни токена истекло
	//authentication.ErrTokenNotFound -  токена в базе данных не существует
	ReadToken(tokenID TokenID) (ProfileID, error)

	//GetProfileIDByEmail должен возвращать такие стандартные ошибки:
	//authentication.ErrEmailNotFound - если профиля с таким E-MAIL не существует
	GetProfileIDByEmail(email string) (profileID ProfileID, err error)

	//GetPasswordByID должен возвращать такие стандартные ошибки:
	//authentication.ErrProfileIdNotFound - если профиля с таким ID не существует
	GetPasswordByID(profileID ProfileID) (password string, err error)

	//GetPasswordByLogin должен возвращать такие стандартные ошибки:
	//authentication.ErrLoginNotFound - если профиля с таким логином не существует
	GetPasswordByLogin(login string) (res *ResultPasswordByLogin, err error)

	//GetLoginByEmail должен возвращать такие стандартные ошибки:
	//authentication.ErrEmailNotFound - если профиля с таким E-MAIL не существует
	GetLoginByEmail(email string) (login string, err error)

	//GetEmail должен возвращать такие стандартные ошибки:
	//authentication.ErrProfileIdNotFound - если профиля с таким ID не существует
	GetEmail(profileID ProfileID) (email string, err error)

	//GetLogin должен возвращать такие стандартные ошибки:
	//authentication.ErrProfileIdNotFound - если профиля с таким ID не существует
	GetLogin(profileID ProfileID) (login string, err error)

	EmailNewSecretKey(key EmailSecretKey, email string, lifetime int64) error
	EmailDeleteSecretKey(key EmailSecretKey) error
	NewToken(tokenID TokenID, profileID ProfileID, lifeTime TokenLifeTime) error
	DelToken(tokenID TokenID, profileID ProfileID) error
	IsUniqueLogin(login string) (bool, error)
	IsUniqueEmail(email string) (bool, error)

	NewProfile(login, email, password string) (ProfileID, error)
	DelProfile(profileID ProfileID) error

	SetPasswordProfileByEmail(email string, password string) error
	SetPasswordProfileByProfileID(profileID ProfileID, password string) error
	SetEmailByProfileID(profileID ProfileID, email string) error
}

func RunSingleflightDriverStorage

func RunSingleflightDriverStorage(st DriverStorage) DriverStorage

type EmailSecretKey

type EmailSecretKey string

type PoolBytesRaw

type PoolBytesRaw struct {
	BS []byte
}

type Profile

type Profile struct {
	ProfileID ProfileID
	// contains filtered or unexported fields
}

func (*Profile) ChangeEmail

func (t *Profile) ChangeEmail(password string) (EmailSecretKey, error)

func (*Profile) ChangePassword

func (t *Profile) ChangePassword(OldPassword, NewPassword string) error

func (*Profile) DeleteProfile

func (t *Profile) DeleteProfile(Password string) error

func (*Profile) GetEmail

func (t *Profile) GetEmail() (string, error)

func (*Profile) GetLogin

func (t *Profile) GetLogin() (string, error)

type ProfileID

type ProfileID int64

type ResultPasswordByLogin

type ResultPasswordByLogin struct {
	ProfileID ProfileID
	Password  string
}

type SingleflightDriverStorage

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

func (*SingleflightDriverStorage) DelProfile

func (sing *SingleflightDriverStorage) DelProfile(profileID ProfileID) error

func (*SingleflightDriverStorage) DelToken

func (sing *SingleflightDriverStorage) DelToken(tokenID TokenID, profileID ProfileID) error

func (*SingleflightDriverStorage) EmailDeleteSecretKey

func (sing *SingleflightDriverStorage) EmailDeleteSecretKey(key EmailSecretKey) error

func (*SingleflightDriverStorage) EmailNewSecretKey

func (sing *SingleflightDriverStorage) EmailNewSecretKey(key EmailSecretKey, email string, lifetime int64) error

func (*SingleflightDriverStorage) EmailReadSecretKey

func (sing *SingleflightDriverStorage) EmailReadSecretKey(key EmailSecretKey) (email string, err error)

func (*SingleflightDriverStorage) GetEmail

func (sing *SingleflightDriverStorage) GetEmail(profileID ProfileID) (email string, err error)

func (*SingleflightDriverStorage) GetLogin

func (sing *SingleflightDriverStorage) GetLogin(profileID ProfileID) (login string, err error)

func (*SingleflightDriverStorage) GetLoginByEmail

func (sing *SingleflightDriverStorage) GetLoginByEmail(email string) (login string, err error)

func (*SingleflightDriverStorage) GetPasswordByID

func (sing *SingleflightDriverStorage) GetPasswordByID(profileID ProfileID) (password string, err error)

func (*SingleflightDriverStorage) GetPasswordByLogin

func (sing *SingleflightDriverStorage) GetPasswordByLogin(login string) (res *ResultPasswordByLogin, err error)

func (*SingleflightDriverStorage) GetProfileIDByEmail

func (sing *SingleflightDriverStorage) GetProfileIDByEmail(email string) (profileID ProfileID, err error)

func (*SingleflightDriverStorage) IsUniqueEmail

func (sing *SingleflightDriverStorage) IsUniqueEmail(email string) (bool, error)

func (*SingleflightDriverStorage) IsUniqueLogin

func (sing *SingleflightDriverStorage) IsUniqueLogin(login string) (bool, error)

func (*SingleflightDriverStorage) NewProfile

func (sing *SingleflightDriverStorage) NewProfile(login, email, password string) (ProfileID, error)

func (*SingleflightDriverStorage) NewToken

func (sing *SingleflightDriverStorage) NewToken(tokenID TokenID, profileID ProfileID, lifeTime TokenLifeTime) error

func (*SingleflightDriverStorage) ReadToken

func (sing *SingleflightDriverStorage) ReadToken(tokenID TokenID) (ProfileID, error)

func (*SingleflightDriverStorage) SetEmailByProfileID

func (sing *SingleflightDriverStorage) SetEmailByProfileID(profileID ProfileID, email string) error

func (*SingleflightDriverStorage) SetPasswordProfileByEmail

func (sing *SingleflightDriverStorage) SetPasswordProfileByEmail(email string, password string) error

func (*SingleflightDriverStorage) SetPasswordProfileByProfileID

func (sing *SingleflightDriverStorage) SetPasswordProfileByProfileID(profileID ProfileID, password string) error

type Token

type Token struct {
	ID       TokenID
	LifeTime TokenLifeTime
	Hash     string
}

type TokenID

type TokenID string

type TokenLifeTime

type TokenLifeTime int64

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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