This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
imagini/internal/auth/local.go

19 lines
497 B
Go
Raw Normal View History

2021-01-10 00:44:02 +00:00
package auth
import (
"golang.org/x/crypto/bcrypt"
log "github.com/sirupsen/logrus"
2021-02-02 20:34:10 +00:00
"reichard.io/imagini/graph/model"
2021-01-10 00:44:02 +00:00
)
2021-02-02 20:34:10 +00:00
func authenticateLocalUser(user model.User, pw string) bool {
2021-01-10 00:44:02 +00:00
bPassword :=[]byte(pw)
2021-02-02 20:34:10 +00:00
err := bcrypt.CompareHashAndPassword([]byte(*user.Password), bPassword)
2021-01-10 00:44:02 +00:00
if err == nil {
2021-01-12 04:48:32 +00:00
log.Info("[auth] Authentication successfull: ", user.Username)
2021-01-10 00:44:02 +00:00
return true
}
2021-01-12 04:48:32 +00:00
log.Warn("[auth] Authentication failed: ", user.Username)
2021-01-10 00:44:02 +00:00
return false
}