CHANGE: added encrypted password auth, TODO: add change and add passwd functions

This commit is contained in:
2025-02-22 13:37:20 +01:00
parent 04f9eb33d4
commit 9987cc226d
7 changed files with 53 additions and 11 deletions

View File

@@ -215,7 +215,7 @@ func (b *Booking) UpdateTime(newTime time.Time){
// TODO: add check for time overlap
var newBooking Booking
newBooking.Timestamp = time.Date(b.Timestamp.Year(), b.Timestamp.Month(), b.Timestamp.Day(), hour, minute, 0, 0, time.Local).UTC()
newBooking.Timestamp = time.Date(b.Timestamp.Year(), b.Timestamp.Month(), b.Timestamp.Day(), hour, minute, 0, 0, time.Local)
if(b.CheckInOut < 3){
newBooking.CheckInOut = b.CheckInOut + 2
}

View File

@@ -2,7 +2,7 @@ package models
import (
"fmt"
"strings"
"log"
)
type User struct {
@@ -94,6 +94,19 @@ func (u *User) GetByPersonalNummer (personalNummer int) (User, error) {
}
func (u *User) Login(password string) bool {
userPassword := strings.ToLower(fmt.Sprintf("%s_%s", u.Vorname, u.Name)) //temp password: "max_mustermann"
return userPassword == password
var loginSuccess bool
qStr, err := DB.Prepare((`SELECT (pass_hash = crypt($2, pass_hash)) AS pass_hash FROM user_password WHERE personal_nummer = $1;`))
if err != nil {
log.Println("Error preparing db statement", err)
return false
}
defer qStr.Close()
err = qStr.QueryRow(u.PersonalNummer, password).Scan(&loginSuccess)
if err != nil {
log.Println("Error queriing db", err)
return false
}
return loginSuccess
// userPassword := strings.ToLower(fmt.Sprintf("%s_%s", u.Vorname, u.Name)) //temp password: "max_mustermann"
// return userPassword == password
}