26 lines
583 B
Go
Raw Permalink Normal View History

2025-07-26 23:31:00 +02:00
package common
import (
"log/slog"
2025-08-23 13:28:48 +02:00
"golang.org/x/crypto/bcrypt"
2025-07-26 23:31:00 +02:00
)
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes), err
}
func (credentials *Credentials) ComparePasswords(password string) bool {
err := bcrypt.CompareHashAndPassword([]byte(password), []byte(credentials.Password))
if err != nil {
slog.Error(err.Error())
return false
}
return true
}
func (credentials *Credentials) HashedPassword() (string, error) {
return HashPassword(credentials.Password)
}