bcrypt

package module
v0.0.0-...-e235017 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: BSD-3-Clause Imports: 7 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

github.com/ProtonMail/bcrypt

A golang implementation of the bcrypt hash algorithm. It is a fork of github.com/jameskeane/bcrypt.

Installation:

go get github.com/ProtonMail/bcrypt

Example use:

package main

import (
      "fmt"
      "github.com/ProtonMail/bcrypt"
)

var password     = "WyWihatdyd?frub1"
var bad_password = "just a wild guess"

func main() {
      // generate a random salt with default rounds of complexity
      salt, _ := bcrypt.Salt()

      // generate a random salt with 10 rounds of complexity
      salt, _ = bcrypt.Salt(10)

      // hash and verify a password with random salt
      hash, _ := bcrypt.Hash(password)
      if bcrypt.Match(password, hash) {
              fmt.Println("They match")
      }

      // hash and verify a password with a static salt
      hash, _ = bcrypt.Hash(password, salt)
      if bcrypt.Match(password, hash) {
              fmt.Println("They match")
      }

      // verify a random password fails to match the hashed password
      if !bcrypt.Match(bad_password, hash) {
              fmt.Println("They don't match")
      }
}

Documentation

Index

Constants

View Source
const (
	MaxRounds      = 31
	MinRounds      = 4
	DefaultRounds  = 12
	SaltLen        = 16
	BlowfishRounds = 16
)

Variables

View Source
var (
	InvalidRounds = errors.New("bcrypt: Invalid rounds parameter")
	InvalidSalt   = errors.New("bcrypt: Invalid salt supplied")
)

Functions

func Hash

func Hash(password string, salt ...string) (ps string, err error)

func HashBytes

func HashBytes(password []byte, salt ...[]byte) (hash []byte, err error)

func Match

func Match(password, hash string) bool

func MatchBytes

func MatchBytes(password []byte, hash []byte) bool

func Salt

func Salt(rounds ...int) (string, error)

Salt generation

func SaltBytes

func SaltBytes(rounds ...int) (salt []byte, err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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