feat: user & article: dev complete

This commit is contained in:
fallen-angle
2022-02-27 16:36:33 +08:00
parent 4f3b16ab9d
commit 80ca1cd46e
33 changed files with 2373 additions and 185 deletions

23
utils/encrypt.go Normal file
View File

@@ -0,0 +1,23 @@
package utils
import (
"crypto/sha256"
"encoding/hex"
"fmt"
"github.com/google/uuid"
)
func PasswordEncrypt(password string) string {
salt := uuid.New().String()[24:]
password = password + salt
shaRes := hex.EncodeToString(sha256.New().Sum([]byte(password)))
encryptPwd := fmt.Sprintf("ncov$%s$%s", shaRes[0:24], salt)
return encryptPwd
}
func PasswordCompare(plaintext string, ciphertext string) (ok bool) {
salt := ciphertext[30:]
password := plaintext + salt
shaRes := hex.EncodeToString(sha256.New().Sum([]byte(password)))
return shaRes[0:24] == ciphertext[5:29]
}