authentication

package
v0.0.0-...-60339a2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CookieCoder = base64.URLEncoding.WithPadding('*')

CookieCoder is a base64 encoding that a web browser can store as a cookie

Functions

func Compare

func Compare(hash, unhashed []byte) bool

Compare compares a hash and a password and returns bool

func Decode

func Decode(input []byte) []byte

Decode Decodes an input byte array and returns the result

func Decrypt

func Decrypt(ciphertext []byte, key []byte) (plaintext []byte)

Decrypt decrypts an input using the key and returns the plaintext result

func Encode

func Encode(input []byte) []byte

Encode CookieEncodes an input byte array and returns the result

func Encrypt

func Encrypt(plaintext []byte, key []byte) (ciphertext []byte)

Encrypt encrypts an input using the key and returns the encrypted result

func Hash

func Hash(plaintext []byte) []byte

Hash bcrypt hashes a byte array and returns it

func NewEncryptionKey

func NewEncryptionKey() []byte

NewEncryptionKey generates a random encryption key

func UserExists

func UserExists(username string, users *mgo.Collection) bool

UserExists checks if user with specified username exists in specified collection

Types

type Matrix

type Matrix map[string]*User

Matrix stores frequently used authkeys

func NewAuthenticationMatrix

func NewAuthenticationMatrix() Matrix

NewAuthenticationMatrix returns a new matrix

type User

type User struct {
	ID       bson.ObjectId `bson:"_id,omitempty"`
	Username string
	Password []byte
	AuthKeys [][]byte
}

User database object for user

func CreateUser

func CreateUser(username, password string, users *mgo.Collection) (*User, error)

CreateUser makes a new user and inserts into specified collection

func FetchUser

func FetchUser(username string, users *mgo.Collection) *User

FetchUser returns a user object from the username

func FindUserByAuthKey

func FindUserByAuthKey(key string, users *mgo.Collection, matrix Matrix) *User

FindUserByAuthKey returns a user object from the authkey

func (*User) Authenticate

func (u *User) Authenticate(encoded string) bool

Authenticate checks authentication key to see if its valid

func (*User) Login

func (u *User) Login(password string, users *mgo.Collection) string

Login logins a user and returns an authentication string

func (*User) UpdateKeys

func (u *User) UpdateKeys(newKey []byte, users *mgo.Collection)

UpdateKeys expires and "old" key and replaces it with a new one

Source Files

  • Encode.go
  • Encrypt.go
  • Hash.go
  • Matrix.go
  • User.go

Jump to

Keyboard shortcuts

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