Parameters for password validation

This commit is contained in:
Nick Penkov
2018-09-21 10:06:27 +02:00
parent 0ff7ac96c8
commit a238d6b9e0
5 changed files with 25 additions and 9 deletions

View File

@ -1,5 +1,5 @@
REPO=npenkov/docker-ldap-passwd-webui
VER=1.1
VER=1.2
.PHONY: all build push

View File

@ -38,6 +38,8 @@ docker run -d -p 8080:8080 --name ldap-passwd-webui \
-e LPW_SSL_SKIP_VERIFY="true" \
-e LPW_USER_DN="uid=%s,ou=people,dc=example,dc=org" \
-e LPW_USER_BASE="ou=people,dc=example,dc=org" \
-e LPW_PATTERN='.{8,}' \
-e LPW_PATTERN_INFO="Password must be at least 8 characters long." \
npenkov/docker-ldap-passwd-webui:latest
```

View File

@ -9,6 +9,14 @@ func getTitle() string {
return envStr("LPW_TITLE", "Change your password on example.org")
}
func getPattern() string {
return envStr("LPW_PATTERN", ".{8,}")
}
func getPatternInfo() string {
return envStr("LPW_PATTERN_INFO", "Password must be at least 8 characters long.")
}
func envStr(key, defaultValue string) string {
val := os.Getenv(key)
if val != "" {

View File

@ -49,6 +49,8 @@ func (h *RegexpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
type pageData struct {
Title string
Pattern string
PatternInfo string
Username string
Alerts map[string]string
CaptchaId string
@ -61,7 +63,7 @@ func ServeAssets(w http.ResponseWriter, req *http.Request) {
// ServeIndex : Serves index page on GET request
func ServeIndex(w http.ResponseWriter, req *http.Request) {
p := &pageData{Title: getTitle(), CaptchaId: captcha.New()}
p := &pageData{Title: getTitle(), CaptchaId: captcha.New(), Pattern: getPattern(), PatternInfo: getPatternInfo()}
t, e := template.ParseFiles(path.Join("templates", "index.html"))
if e != nil {
log.Printf("Error parsing file %v\n", e)
@ -102,6 +104,10 @@ func ChangePassword(w http.ResponseWriter, req *http.Request) {
alerts["error"] = "New and confirmation passwords does not match. "
}
if m, _ := regexp.MatchString(getPattern(), newPassword[0]); !m {
alerts["error"] = alerts["error"] + fmt.Sprintf("%s", getPatternInfo())
}
if len(captchaID) < 1 || captchaID[0] == "" ||
len(captchaSolution) < 1 || captchaSolution[0] == "" ||
!captcha.VerifyString(captchaID[0], captchaSolution[0]) {

View File

@ -54,12 +54,12 @@
<label for="new-password">New password</label>
<input id="new-password" name="new-password" type="password"
pattern=".{8,}" x-moz-errormessage="Password must be at least 8 characters long." required>
pattern="{{.Pattern}}" x-moz-errormessage="{{.PatternInfo}}" required>
<label for="confirm-password">Confirm new password</label>
<input id="confirm-password" name="confirm-password" type="password"
pattern=".{8,}" x-moz-errormessage="Password must be at least 8 characters long." required>
pattern="{{.Pattern}}" x-moz-errormessage="{{.PatternInfo}}" required>
<p>{{.PatternInfo}}</p>
<p>Type the numbers you see in the picture below:</p>
<p>
<img id=image src="/captcha/{{.CaptchaId}}.png" alt="Captcha image">