2021-02-02 17:59:24 +01:00
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type User struct {
|
2021-02-05 11:19:27 +01:00
|
|
|
Id *int64 `json:"id"`
|
|
|
|
Username *string `json:"username"`
|
|
|
|
PasswordHash *string `json:"password_hash"`
|
|
|
|
Password *string `json:"password"` // Only used in update.
|
2021-02-02 17:59:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func New(id int64, username string, password_hash string) User {
|
2021-02-05 11:19:27 +01:00
|
|
|
return User{
|
|
|
|
Id: &id,
|
|
|
|
Username: &username,
|
|
|
|
PasswordHash: &password_hash,
|
|
|
|
}
|
2021-02-02 17:59:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (self User) CheckPassword(password string) bool {
|
2021-02-05 11:19:27 +01:00
|
|
|
err := bcrypt.CompareHashAndPassword([]byte(*(self.PasswordHash)), []byte(password))
|
2021-02-02 17:59:24 +01:00
|
|
|
return err == nil
|
|
|
|
}
|