Skip to content
Node: bcrypt.hash(password, 10)github.com/sahilkhaire/gox/crypto

HashPassword

Overview ​

HashPassword hashes password with bcrypt (bcrypt.hash).

If you are coming from Node.js, the closest pattern is bcrypt.hash(password, 10).

Signature ​

go
func HashPassword(password string) (string, error)

Compare: Node.js · Standard Go · gox ​

js
await bcrypt.hash(password, 10);
go
hash, err := bcrypt.GenerateFromPassword([]byte(pw), bcrypt.DefaultCost)
go
import "github.com/sahilkhaire/gox/crypto"

hash, err := crypto.HashPassword(password)

Example ​

go
import "github.com/sahilkhaire/gox/crypto"

hash, err := crypto.HashPassword(password)

Tips ​

Import github.com/sahilkhaire/gox/crypto and call HashPassword directly. See the comparison below for the standard library equivalent.

Standard library alternative ​

Use the standard library directly:

go
hash, err := bcrypt.GenerateFromPassword([]byte(pw), bcrypt.DefaultCost)

← Back to crypto package overview

MIT Licensed · Built for Node.js developers moving to Go