auth

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2024 License: MIT Imports: 7 Imported by: 0

README

auth

bcrypt wrapper to provide auth structs and methods

Documentation

Overview

package auth wraps bcrypt to provide some basic functionality, adding a Token object which combines a distinct user id with that users secret to make a token in format <id>:<secret>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(hash string, plaintext string) (bool, error)

Compare compares a provided string to an expected string. NOTE: make sure you're comparing *tokens* (<id>:<secret>) and not just the secret

func Cost

func Cost(secret string) (int, error)

Cost calculates the cost of the hash

func Hash

func Hash(plaintext string, cost int) (string, error)

Hash uses bcrypt to create a Hash from plaintext password

func NewSecret

func NewSecret(length int) (string, error)

NewSecret creates a new base64 encoded secret

func NewToken

func NewToken(userID int, secret string) string

NewToken formats into standard '<id>:<secret>'

Types

type Token

type Token struct {
	Id     int    // correlates with db: users.id
	Secret string // correlates with hashed db: users.hashed_secret
}

func ParseToken

func ParseToken(token string) (Token, error)

ParseToken takes a token in '<id>:<secret>' format and returns a Token struct

func (*Token) Format

func (t *Token) Format() string

Format takes 'id' and 'secret' and formats a string as '<id>:<secret>'

Jump to

Keyboard shortcuts

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