From 986cec21a4533a0c69771570312fad3a10fe763d Mon Sep 17 00:00:00 2001 From: celogeek Date: Tue, 1 Feb 2022 09:41:47 +0100 Subject: [PATCH] add method to encrypt password --- internal/photos/models/account.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/photos/models/account.go b/internal/photos/models/account.go index ffc45c1..2729136 100644 --- a/internal/photos/models/account.go +++ b/internal/photos/models/account.go @@ -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 }