Skip to content

Instantly share code, notes, and snippets.

@suciptoid
Created April 28, 2018 12:37
Show Gist options
  • Save suciptoid/9c556ccc8b1831c2d7dbbd96c7b64797 to your computer and use it in GitHub Desktop.
Save suciptoid/9c556ccc8b1831c2d7dbbd96c7b64797 to your computer and use it in GitHub Desktop.
bcrypt implementation sample in Go
package main
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
func main() {
password := "MySecretPassowrd"
bytePassword := []byte(password)
hash, _ := bcrypt.GenerateFromPassword(bytePassword, bcrypt.DefaultCost)
var isMatch bool
if err := bcrypt.CompareHashAndPassword([]byte(hash), bytePassword); err != nil {
isMatch = false
} else {
isMatch = true
}
fmt.Println("Password\t:", password)
fmt.Println("Hashed Password\t:", string(hash))
fmt.Println("Is Hashed Match\t:", isMatch)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment