20 lines
475 B
Go
20 lines
475 B
Go
|
package util
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"golang.org/x/crypto/bcrypt"
|
||
|
)
|
||
|
|
||
|
func HashPassword(password string) (string, error) {
|
||
|
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||
|
if err != nil {
|
||
|
return "", fmt.Errorf("Failed to hash password: %w", err)
|
||
|
}
|
||
|
return string(hashedPassword), nil
|
||
|
}
|
||
|
|
||
|
func CheckPassword(password string, hashedPassword string) error {
|
||
|
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
|
||
|
}
|