bcrypt

package
Version: v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: MIT Imports: 5 Imported by: 0

README

PHC Crypto - Bcrypt

Go Reference

According to Wikipedia:

bcrypt is a password-hashing function designed by Niels Provos and David Mazières, based on the Blowfish cipher and presented at USENIX in 1999. Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with increasing computation power.

Configuration options

Key Type Default Notes
Rounds int 10 Cost of rounds, minimum of 4, maximum of 31.

Usage with PHC Crypto

$ go get github.com/aldy505/phc-crypto
import (
  "fmt"
  "github.com/aldy505/phc-crypto"
)

func main() {
  crypto, err := phccrypto.Use(phccrypto.Bcrypt, phccrypto.Config{
    Rounds: 20,
  })
  if err != nil {
    fmt.Println(err)
  }

  hash, err := phccrypto.Hash("password")
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(hash) // $bcrypt$v=0$r=12$$2432612431322479356256373563666e503557...

  verify, err := phccrypto.Verify(hash, "password")
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(verify) // true
}

Standalone usage

$ go get github.com/aldy505/phc-crypto/bcrypt
import (
  "fmt"
  "github.com/aldy505/phc-crypto/bcrypt"
)

func main() {

  hash, err := bcrypt.Hash("password", bcrypt.Config{
    Rounds: 12,
  })
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(hash) // $bcrypt$v=0$r=12$$2432612431322479356256373563666e503557...

  verify, err := bcrypt.Verify(hash, "password")
  if err != nil {
    fmt.Println(err)
  }
  fmt.Println(verify) // true
}

Documentation

Index

Constants

View Source
const (
	// ROUNDS is the cost of rounds, minimum of 4, maximum of 31.
	ROUNDS = 10
)

Variables

This section is empty.

Functions

func Hash

func Hash(plain string, config Config) (string, error)

Hash creates a PHC-formatted hash with config provided

func Verify

func Verify(hash string, plain string) (bool, error)

Verify checks the hash if it's equal (by an algorithm) to plain text provided.

Types

type Config

type Config struct {
	Rounds int
}

Config initialize the config require to create a hash function

Source Files

Jump to

Keyboard shortcuts

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