Created
May 10, 2021 04:44
-
-
Save boseji/97dcbbc36d471e33fa6a34aba3683c5f to your computer and use it in GitHub Desktop.
bcrypt for Passwords
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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