user

package
v0.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package user provides management of user accounts.

Index

Constants

View Source
const (

	// ScryptHashVersion is the version representation of the scrypt algorithm.
	ScryptHashVersion = 1

	// Pbkdf2HashVersion is the version representation of the pbkdf2 algorithm.
	Pbkdf2HashVersion = 2
)
View Source
const ManifestType = "user"

ManifestType is the type of the manifest used to represent user accounts.

View Source
const UsernameAtHostnameLabel = "username"

UsernameAtHostnameLabel is the manifest label identifying users by username@hostname.

Variables

View Source
var ErrUserAlreadyExists = errors.New("user already exists")

ErrUserAlreadyExists indicates that a user already exist in the system when attempting to create a new one.

View Source
var ErrUserNotFound = errors.New("user not found")

ErrUserNotFound is returned to indicate that a user was not found in the system.

Functions

func DeleteUserProfile

func DeleteUserProfile(ctx context.Context, w repo.RepositoryWriter, username string) error

DeleteUserProfile removes user profile with a given username.

func HashPassword added in v0.18.0

func HashPassword(password string) (string, error)

HashPassword computes the hash for the given password and an encoded hash that can be passed to Profile.SetPasswordHash().

func LoadProfileMap

func LoadProfileMap(ctx context.Context, rep repo.Repository, old map[string]*Profile) (map[string]*Profile, error)

LoadProfileMap returns the map of all users profiles in the repository by username, using old map as a cache.

func SetUserProfile

func SetUserProfile(ctx context.Context, w repo.RepositoryWriter, p *Profile) error

SetUserProfile creates or updates user profile.

func ValidateUsername

func ValidateUsername(name string) error

ValidateUsername returns an error if the given username is invalid.

Types

type Profile

type Profile struct {
	ManifestID manifest.ID `json:"-"`

	Username            string `json:"username"`
	PasswordHashVersion int    `json:"passwordHashVersion,omitempty"`
	PasswordHash        []byte `json:"passwordHash"`
}

Profile describes information about a single user.

func GetNewProfile added in v0.18.0

func GetNewProfile(ctx context.Context, r repo.Repository, username string) (*Profile, error)

GetNewProfile returns a profile for a new user with the given username. Returns ErrUserAlreadyExists when the user already exists.

func GetUserProfile

func GetUserProfile(ctx context.Context, r repo.Repository, username string) (*Profile, error)

GetUserProfile returns the user profile with a given username. Returns ErrUserNotFound when the user does not exist.

func ListUserProfiles

func ListUserProfiles(ctx context.Context, rep repo.Repository) ([]*Profile, error)

ListUserProfiles gets the list of all user profiles in the system.

func (*Profile) IsValidPassword

func (p *Profile) IsValidPassword(password string) (bool, error)

IsValidPassword determines whether the password is valid for a given user.

func (*Profile) SetPassword

func (p *Profile) SetPassword(password string) error

SetPassword changes the password for a user profile.

func (*Profile) SetPasswordHash added in v0.18.0

func (p *Profile) SetPasswordHash(encodedHash string) error

SetPasswordHash decodes and validates encodedhash, if it is a valid hash then it sets it as the password hash for the user profile.

Jump to

Keyboard shortcuts

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