Example #1
0
func NewHtpasswdWatchingBasicAuth(realm, htpasswdFile string) (auth *HtpasswdWatchingBasicAuth, err error) {
	auth = &HtpasswdWatchingBasicAuth{
		basicAuth:    BasicAuth{Realm: realm},
		htpasswdFile: htpasswdFile,
	}
	auth.basicAuth.UserPassword, auth.htpasswdFileTime, err = utils.ReadHtpasswdFile(htpasswdFile)
	if err != nil {
		return nil, err
	}
	return auth, nil
}
Example #2
0
func (auth *HtpasswdWatchingBasicAuth) Authenticate(ctx *Context) (ok bool, err error) {
	auth.mutex.Lock()
	defer auth.mutex.Unlock()

	t, err := utils.FileModifiedTime(auth.htpasswdFile)
	if err != nil {
		return false, err
	}

	if t.After(auth.htpasswdFileTime) {
		auth.basicAuth.UserPassword, auth.htpasswdFileTime, err = utils.ReadHtpasswdFile(auth.htpasswdFile)
		if err != nil {
			return false, err
		}
	}

	return auth.basicAuth.Authenticate(ctx)
}