add method to encrypt password

This commit is contained in:
celogeek 2022-02-01 09:41:47 +01:00
parent 6b1d4756bc
commit 986cec21a4
Signed by: celogeek
GPG Key ID: E6B7BDCFC446233A

View File

@ -18,8 +18,12 @@ type Account struct {
}
func (a *Account) BeforeCreate(tx *gorm.DB) error {
a.EncryptPassword()
return nil
}
func (a *Account) EncryptPassword() {
sha1 := crypto.SHA256.New()
sha1.Write([]byte(a.Password))
a.EncryptedPassword = base64.StdEncoding.EncodeToString(sha1.Sum(nil))
return nil
}