security

package
v0.0.0-...-b31fe97 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MinPasswordLength = 8

MinPasswordLength is the minimum length of a password.

Variables

View Source
var ErrCannotGenerateRandomBytes = errors.New("cannot generate random bytes")

ErrCannotGenerateRandomBytes is the error returned when we cannot generate a random string

View Source
var ErrCannotGenerateRandomString = errors.New("cannot generate random token")

ErrCannotGenerateRandomString is the error returned when we cannot generate a random string

View Source
var ErrLength = errors.New("password should have more than 8 characters.")

ErrLength is an error that is returned when the password is not 8 characters long

View Source
var ErrLowercase = errors.New("password should have a minimum of 1 lower case letter [a-z].")

ErrLowercase is an error that is returned when the password does not contain any lowercase characters

View Source
var ErrNoTokenPresent = errors.New("no token present")

ErrNoTokenPresent is returned when no token is present

View Source
var ErrNumeric = errors.New("password should have a minimum of 1 numeric character! e.g. 1,..,9,0.")

ErrNumeric is an error that is returned when the password does not contain any numeric characters

View Source
var ErrSpecial = errors.New("password should have a minimum of 1 special character: ~!@#$%^&*()-_+={}[]|:<>,./?...")

ErrSpecial is an error that is returned when the password does not contain any special characters

View Source
var ErrTokenNotValid = errors.New("token not valid")

ErrTokenNotValid is returned when the token is not valid

View Source
var ErrUppercase = errors.New("password should have a minimum of 1 upper case letter [A-Z].")

ErrUppercase is an error that is returned when the password does not contain any uppercase characters

Functions

func CheckPasswordComplexity

func CheckPasswordComplexity(password string) (err error)

CheckPasswordComplexity checks if the user password matches the conditions

func GenerateEmailChangeToken

func GenerateEmailChangeToken(email string, expirationDate time.Time) (string, error)

GenerateEmailChangeToken generate a token to verify a new email address

func GenerateJWTToken

func GenerateJWTToken(subjectUID uuid.UUID, audience string, payload map[string]interface{}) (tokenString string, tokenUID uuid.UUID, err error)

GenerateJWTToken generate token for as user and a payload

func GenerateJWTTokenWithExpirationData

func GenerateJWTTokenWithExpirationData(subjectUID uuid.UUID, audience string, payload map[string]interface{}, utcExpirationDate time.Time) (tokenString string, tokenUID uuid.UUID, err error)

GenerateJWTTokenWithExpirationData generate token for as user and a payload with expiration date

func GeneratePasswordResetToken

func GeneratePasswordResetToken(email string, expirationDate time.Time) (string, error)

GeneratePasswordResetToken generate a password reset token with an expiration date

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes returns securely generated random bytes. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GenerateRandomString

func GenerateRandomString(s int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func HashPassword

func HashPassword(pepper string, password string, salt []byte) (hashedPassword []byte, hashedSalt []byte)

HashPassword hashes the users password and also generates a specific salt per user

func ParseToken

func ParseToken(tokenString string) (claims map[string]interface{}, err error)

ParseToken takes a string and extracts the token

func ValidatePassword

func ValidatePassword(password string) (length, number, upper, lower, special bool)

ValidatePassword validates the user's password seven or more characters, special, ...

Types

This section is empty.

Jump to

Keyboard shortcuts

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