RestApiv2/pkg/utils/password/password.go

23 lines
414 B
Go
Raw Normal View History

2023-04-14 17:35:25 +03:00
package password
import (
"golang.org/x/crypto/bcrypt"
)
2023-04-14 17:35:25 +03:00
func HashPassword(password string) (*[]byte, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
if err != nil {
return nil, err
}
return &bytes, err
}
func CheckValid(password string, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
if err != nil {
return false
}
return true
}