Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Reduce password strength verification when using on the intranet #966

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions web/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ const (
digitsChars = `0123456789`
)

// validate 检查密码强度是否大于最低要求(50)。如果不是则返回错误并说明如何加强密码。向客户端显示此错误是安全的。
func validate(password string) error {
return validatePassword(password, 50)
}

// validatePassword 在密码大于或等于 minEntropy 时返回 nil。如果不是则返回错误。
// 这解释了如何加强密码。向客户端显示此错误是安全的。
//
Expand Down
20 changes: 12 additions & 8 deletions web/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ func checkAndSave(request *http.Request) string {

}

// 如果密码不为空则检查是否够强
if passwordNew != "" {
err = validate(passwordNew)
if err != nil {
return err.Error()
}
}

conf.NotAllowWanAccess = request.FormValue("NotAllowWanAccess") == "on"
conf.Username = usernameNew
conf.Password = passwordNew
Expand All @@ -70,6 +62,18 @@ func checkAndSave(request *http.Request) string {
return "启用外网访问, 必须输入登录用户名/密码"
}

// 如果密码不为空则检查是否够强, 内/外网要求强度不同
if passwordNew != "" {
var minEntropyBits float64 = 50
if conf.NotAllowWanAccess {
minEntropyBits = 25
}
err = validatePassword(passwordNew, minEntropyBits)
if err != nil {
return err.Error()
}
}

dnsConfFromJS := []dnsConf4JS{}
err = json.Unmarshal([]byte(request.FormValue("DnsConf")), &dnsConfFromJS)
if err != nil {
Expand Down