20 lines
446 B
Go
20 lines
446 B
Go
|
|
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
|
|||
|
|
}
|