feat: user & article: dev complete
This commit is contained in:
23
utils/encrypt.go
Normal file
23
utils/encrypt.go
Normal 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]
|
||||
}
|
||||
Reference in New Issue
Block a user