2020-03-04 10:29:00 +00:00
|
|
|
package users
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-06-06 00:36:39 +00:00
|
|
|
"github.com/statping/statping/utils"
|
2020-03-04 10:29:00 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AuthUser will return the User and a boolean if authentication was correct.
|
|
|
|
// AuthUser accepts username, and password as a string
|
|
|
|
func AuthUser(username, password string) (*User, bool) {
|
|
|
|
user, err := FindByUsername(username)
|
|
|
|
if err != nil {
|
|
|
|
log.Warnln(fmt.Errorf("user %v not found", username))
|
|
|
|
return nil, false
|
|
|
|
}
|
2020-06-06 00:36:39 +00:00
|
|
|
if utils.CheckHash(password, user.Password) {
|
2020-03-04 10:29:00 +00:00
|
|
|
user.UpdatedAt = time.Now().UTC()
|
|
|
|
user.Update()
|
|
|
|
return user, true
|
|
|
|
}
|
|
|
|
return nil, false
|
|
|
|
}
|