Parameters for password validation
This commit is contained in:
2
Makefile
2
Makefile
@ -1,5 +1,5 @@
|
|||||||
REPO=npenkov/docker-ldap-passwd-webui
|
REPO=npenkov/docker-ldap-passwd-webui
|
||||||
VER=1.0
|
VER=1.2
|
||||||
|
|
||||||
.PHONY: all build push
|
.PHONY: all build push
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ docker run -d -p 8080:8080 --name ldap-passwd-webui \
|
|||||||
-e LPW_SSL_SKIP_VERIFY="true" \
|
-e LPW_SSL_SKIP_VERIFY="true" \
|
||||||
-e LPW_USER_DN="uid=%s,ou=people,dc=example,dc=org" \
|
-e LPW_USER_DN="uid=%s,ou=people,dc=example,dc=org" \
|
||||||
-e LPW_USER_BASE="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
|
npenkov/docker-ldap-passwd-webui:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -9,6 +9,14 @@ func getTitle() string {
|
|||||||
return envStr("LPW_TITLE", "Change your password on example.org")
|
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 {
|
func envStr(key, defaultValue string) string {
|
||||||
val := os.Getenv(key)
|
val := os.Getenv(key)
|
||||||
if val != "" {
|
if val != "" {
|
||||||
|
25
app/web.go
25
app/web.go
@ -43,9 +43,11 @@ func (h *RegexpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type pageData struct {
|
type pageData struct {
|
||||||
Title string
|
Title string
|
||||||
Username string
|
Pattern string
|
||||||
Alerts map[string]string
|
PatternInfo string
|
||||||
|
Username string
|
||||||
|
Alerts map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeAssets : Serves the static assets
|
// ServeAssets : Serves the static assets
|
||||||
@ -55,7 +57,7 @@ func ServeAssets(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
// ServeIndex : Serves index page on GET request
|
// ServeIndex : Serves index page on GET request
|
||||||
func ServeIndex(w http.ResponseWriter, req *http.Request) {
|
func ServeIndex(w http.ResponseWriter, req *http.Request) {
|
||||||
p := &pageData{Title: getTitle()}
|
p := &pageData{Title: getTitle(), Pattern: getPattern(), PatternInfo: getPatternInfo()}
|
||||||
t, e := template.ParseFiles(path.Join("templates", "index.html"))
|
t, e := template.ParseFiles(path.Join("templates", "index.html"))
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Printf("Error parsing file %v\n", e)
|
log.Printf("Error parsing file %v\n", e)
|
||||||
@ -76,23 +78,28 @@ func ChangePassword(w http.ResponseWriter, req *http.Request) {
|
|||||||
alerts := map[string]string{}
|
alerts := map[string]string{}
|
||||||
|
|
||||||
if len(username) < 1 || username[0] == "" {
|
if len(username) < 1 || username[0] == "" {
|
||||||
alerts["error"] = "Username not specified.<br/>"
|
alerts["error"] = "Username not specified."
|
||||||
} else {
|
} else {
|
||||||
un = username[0]
|
un = username[0]
|
||||||
}
|
}
|
||||||
if len(oldPassword) < 1 || oldPassword[0] == "" {
|
if len(oldPassword) < 1 || oldPassword[0] == "" {
|
||||||
alerts["error"] = alerts["error"] + "Old password not specified.<br/>"
|
alerts["error"] = alerts["error"] + "Old password not specified."
|
||||||
}
|
}
|
||||||
if len(newPassword) < 1 || newPassword[0] == "" {
|
if len(newPassword) < 1 || newPassword[0] == "" {
|
||||||
alerts["error"] = alerts["error"] + "New password not specified.<br/>"
|
alerts["error"] = alerts["error"] + "New password not specified."
|
||||||
}
|
}
|
||||||
if len(confirmPassword) < 1 || confirmPassword[0] == "" {
|
if len(confirmPassword) < 1 || confirmPassword[0] == "" {
|
||||||
alerts["error"] = alerts["error"] + "Confirmation password not specified.<br/>"
|
alerts["error"] = alerts["error"] + "Confirmation password not specified."
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(confirmPassword) >= 1 && len(newPassword) >= 1 && strings.Compare(newPassword[0], confirmPassword[0]) != 0 {
|
if len(confirmPassword) >= 1 && len(newPassword) >= 1 && strings.Compare(newPassword[0], confirmPassword[0]) != 0 {
|
||||||
alerts["error"] = alerts["error"] + "New and confirmation passwords does not match.<br/>"
|
alerts["error"] = 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(alerts) == 0 {
|
if len(alerts) == 0 {
|
||||||
client := NewLDAPClient()
|
client := NewLDAPClient()
|
||||||
if err := client.ModifyPassword(un, oldPassword[0], newPassword[0]); err != nil {
|
if err := client.ModifyPassword(un, oldPassword[0], newPassword[0]); err != nil {
|
||||||
|
@ -24,12 +24,12 @@
|
|||||||
|
|
||||||
<label for="new-password">New password</label>
|
<label for="new-password">New password</label>
|
||||||
<input id="new-password" name="new-password" type="password"
|
<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>
|
<label for="confirm-password">Confirm new password</label>
|
||||||
<input id="confirm-password" name="confirm-password" type="password"
|
<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>
|
||||||
<button type="submit">Update password</button>
|
<button type="submit">Update password</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user