Darius klein fcd0f88f52
Some checks failed
build and deploy kleinTodo / build (push) Failing after 28s
refactor + added client
2025-08-23 13:28:48 +02:00

26 lines
583 B
Go

package common
import (
"log/slog"
"golang.org/x/crypto/bcrypt"
)
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)
}