commit
This commit is contained in:
19
go_backend/utils/password.go
Normal file
19
go_backend/utils/password.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// HashPassword 密码加密(使用SHA256,与Python版本保持一致)
|
||||
func HashPassword(password string) string {
|
||||
hash := sha256.Sum256([]byte(password))
|
||||
return hex.EncodeToString(hash[:])
|
||||
}
|
||||
|
||||
// VerifyPassword 验证密码
|
||||
func VerifyPassword(password, hashedPassword string) bool {
|
||||
fmt.Printf(HashPassword(password))
|
||||
return HashPassword(password) == hashedPassword
|
||||
}
|
||||
Reference in New Issue
Block a user