mirror of
https://github.com/ngoduykhanh/wireguard-ui.git
synced 2025-07-13 18:18:15 +03:00
Merge branch 'master' into clients-patch
# Conflicts: # util/util.go
This commit is contained in:
commit
59a4ade8c6
14 changed files with 128 additions and 33 deletions
|
@ -11,6 +11,7 @@ var (
|
|||
SmtpUsername string
|
||||
SmtpPassword string
|
||||
SmtpNoTLSCheck bool
|
||||
SmtpEncryption string
|
||||
SmtpAuthType string
|
||||
SendgridApiKey string
|
||||
EmailFrom string
|
||||
|
@ -34,6 +35,7 @@ const (
|
|||
DefaultConfigFilePath = "/etc/wireguard/wg0.conf"
|
||||
UsernameEnvVar = "WGUI_USERNAME"
|
||||
PasswordEnvVar = "WGUI_PASSWORD"
|
||||
PasswordHashEnvVar = "WGUI_PASSWORD_HASH"
|
||||
EndpointAddressEnvVar = "WGUI_ENDPOINT_ADDRESS"
|
||||
DNSEnvVar = "WGUI_DNS"
|
||||
MTUEnvVar = "WGUI_MTU"
|
||||
|
|
30
util/hash.go
Normal file
30
util/hash.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
func HashPassword(plaintext string) (string, error) {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(plaintext), 14)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("cannot hash password: %w", err)
|
||||
}
|
||||
return base64.StdEncoding.EncodeToString(bytes), nil
|
||||
}
|
||||
|
||||
func VerifyHash(base64Hash string, plaintext string) (bool, error) {
|
||||
hash, err := base64.StdEncoding.DecodeString(base64Hash)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("cannot decode base64 hash: %w", err)
|
||||
}
|
||||
err = bcrypt.CompareHashAndPassword(hash, []byte(plaintext))
|
||||
if err == bcrypt.ErrMismatchedHashAndPassword {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("cannot verify password: %w", err)
|
||||
}
|
||||
return true, nil
|
||||
}
|
|
@ -28,6 +28,11 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G
|
|||
if client.UseServerDNS {
|
||||
clientDNS = fmt.Sprintf("DNS = %s\n", strings.Join(setting.DNSServers, ","))
|
||||
}
|
||||
clientMTU := ""
|
||||
if setting.MTU > 0 {
|
||||
clientMTU = fmt.Sprintf("MTU = %d\n", setting.MTU)
|
||||
}
|
||||
|
||||
clientPostUp := ""
|
||||
if strings.TrimSpace(client.PostUp) != "" {
|
||||
clientPostUp = fmt.Sprintf("PostUp = %s\n", client.PostUp)
|
||||
|
@ -74,6 +79,7 @@ func BuildClientConfig(client model.Client, server model.Server, setting model.G
|
|||
clientAddress +
|
||||
clientPrivateKey +
|
||||
clientDNS +
|
||||
clientMTU +
|
||||
forwardMark +
|
||||
clientPostUp +
|
||||
clientPostDown +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue