Created
April 28, 2018 12:37
-
-
Save suciptoid/9c556ccc8b1831c2d7dbbd96c7b64797 to your computer and use it in GitHub Desktop.
bcrypt implementation sample in Go
This file contains hidden or 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
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