forked from mtusi2026/mtusi2026lab3
18 lines
385 B
Go
18 lines
385 B
Go
package password
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
const bcryptCost = 10
|
|
|
|
func Hash(password string) (string, error) {
|
|
hashed, err := bcrypt.GenerateFromPassword([]byte(password), bcryptCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(hashed), nil
|
|
}
|
|
|
|
func Check(password, hash string) bool {
|
|
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
|
|
}
|