26 lines
559 B
Go
26 lines
559 B
Go
package models
|
|
|
|
import (
|
|
"crypto"
|
|
"encoding/base64"
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
type Account struct {
|
|
ID uint32 `gorm:"primary_key"`
|
|
Login string `gorm:"unique;size:64;not null"`
|
|
Password string `gorm:"-"`
|
|
EncryptedPassword string `gorm:"size:44;not null"`
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
func (a *Account) BeforeCreate(tx *gorm.DB) error {
|
|
sha1 := crypto.SHA256.New()
|
|
sha1.Write([]byte(a.Password))
|
|
a.EncryptedPassword = base64.StdEncoding.EncodeToString(sha1.Sum(nil))
|
|
return nil
|
|
}
|