36 lines
747 B
Go
36 lines
747 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"github.com/jinzhu/gorm"
|
||
|
|
||
|
liblog "dev.sum7.eu/sum7/warehost/lib/log"
|
||
|
libpassword "dev.sum7.eu/sum7/warehost/lib/password"
|
||
|
system "dev.sum7.eu/sum7/warehost/system"
|
||
|
)
|
||
|
|
||
|
type WarehostAuth struct {
|
||
|
db *gorm.DB
|
||
|
}
|
||
|
|
||
|
func (this WarehostAuth) CheckPasswd(user, pass string) (returndata bool, err error) {
|
||
|
returndata = false
|
||
|
var login = system.Login{Username: user}
|
||
|
this.db.Where("mail = ?", user).First(&login)
|
||
|
if login.ID <= 0 {
|
||
|
liblog.Log.Warn("user not found")
|
||
|
return
|
||
|
}
|
||
|
if login.Active {
|
||
|
output, _ := libpassword.Validate(login.Password, pass)
|
||
|
if output {
|
||
|
returndata = true
|
||
|
liblog.Log.Info("done")
|
||
|
} else {
|
||
|
liblog.Log.Warn("wrong password")
|
||
|
}
|
||
|
} else {
|
||
|
liblog.Log.Warn("not active")
|
||
|
}
|
||
|
return
|
||
|
}
|