passwords

package
v6.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2022 License: Apache-2.0 Imports: 1 Imported by: 0

README

Passwords

This package provides basic tools for hashing password.

Hashing

To create a hashed password:

hashedPassword, err := passwords.HashPassword("password")

Validation

To validate a plaintext password matches your hashed password:

matches := passwords.IsPasswordValid(hashedPassword, "password")

Custom Hashed Password Type

This package also provides a custom type, HashedPasswordString which provides a convienent way of working with passwords that you wish to hash and verify. As an example, here is a struct that contains a password field that you may wish to hash prior to saving in a database.

type MyStruct struct {
	Name string                             `json:"name"`
	Password passwords.HashedPasswordString `json:"password"`
}

// Let's pretent we have a user-submitted form that has populated this struct...
u := MyStruct{
	Name: "Adam",
	Password: "password",
}

// Save to imaginary database...
name := u.Name
password := u.Password.Hash()

Documentation

Overview

* Copyright (c) 2021. App Nerds LLC. All rights reserved

* Copyright (c) 2021. App Nerds LLC. All rights reserved

* Copyright (c) 2021. App Nerds LLC. All rights reserved

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HashPassword

func HashPassword(password string) (string, error)

HashPassword takes a password as a string and returns a hex encoded bcrypted representation.

func IsPasswordValid

func IsPasswordValid(hashedPassword, plaintextPassword string) bool

IsPasswordValid takes a hashed password and a plaintext version and returns

Types

type HashedPasswordString

type HashedPasswordString string

HashedPasswordString is a type of string that represents a hashed password. This is often useful when dealing with passwords that must be stored in a database.

func (HashedPasswordString) Hash

func (HashedPasswordString) IsEmpty

func (hp HashedPasswordString) IsEmpty() bool

func (HashedPasswordString) IsSameAsPlaintextPassword

func (hp HashedPasswordString) IsSameAsPlaintextPassword(plaintextPassword string) bool

Jump to

Keyboard shortcuts

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