add method to encrypt password
This commit is contained in:
parent
6b1d4756bc
commit
986cec21a4
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user