passwords

package
v6.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: Apache-2.0 Imports: 1 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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