Skip to content

Instantly share code, notes, and snippets.

@boseji
Created May 10, 2021 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boseji/97dcbbc36d471e33fa6a34aba3683c5f to your computer and use it in GitHub Desktop.
Save boseji/97dcbbc36d471e33fa6a34aba3683c5f to your computer and use it in GitHub Desktop.
bcrypt for Passwords
// Copyright 2021 Abhijit Bose. All rights reserved.
// Use of this source code is governed by a Apache 2.0 license
package main
import (
"fmt"
"encoding/hex"
"golang.org/x/crypto/bcrypt"
)
func main() {
b, _ := bcrypt.GenerateFromPassword(
[]byte("Test Password"),
bcrypt.DefaultCost,
)
fmt.Println(hex.EncodeToString(b))
}
// Copyright 2021 Abhijit Bose. All rights reserved.
// Use of this source code is governed by a Apache 2.0 license
package main
import (
"encoding/hex"
"fmt"
"golang.org/x/crypto/bcrypt"
)
func main() {
password := []byte("Test Password")
hash, _ := hex.DecodeString("2432612431302478775774465351745a4f755431624e77673646766565686a77424e68715a3035634e6e456e557a5549736b79324e316461524f3243")
err := bcrypt.CompareHashAndPassword(
hash, password,
)
fmt.Println(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment