mirror of
https://github.com/VaalaCat/frp-panel.git
synced 2025-12-24 11:51:06 +08:00
33 lines
646 B
Go
33 lines
646 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"crypto/sha1"
|
|
"encoding/hex"
|
|
"fmt"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func MD5(input string) string {
|
|
data := []byte(input)
|
|
hash := md5.Sum(data)
|
|
hashString := hex.EncodeToString(hash[:])
|
|
return hashString
|
|
}
|
|
|
|
func SHA1(input string) string {
|
|
hash := sha1.Sum([]byte(input))
|
|
return fmt.Sprintf("%x", hash)
|
|
}
|
|
|
|
func HashPassword(password string) (string, error) {
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
|
return string(bytes), err
|
|
}
|
|
|
|
func CheckPasswordHash(password, hash string) bool {
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
return err == nil
|
|
}
|