Skip to content

Instantly share code, notes, and snippets.

@thebigbad
Created May 2, 2012 04:06
Show Gist options
  • Save thebigbad/2573539 to your computer and use it in GitHub Desktop.
Save thebigbad/2573539 to your computer and use it in GitHub Desktop.
func authorized(r *http.Request) bool {
h := r.Header.Get("Authorization")
_, password, err := basicauth.Decode(h)
if err != nil {
return false
}
c := appengine.NewContext(r)
k := datastore.NewKey(c, "Password", "password", 0, nil)
p := new(Password)
if err := datastore.Get(c, k, p); err != nil {
// If password is not set, seed with whatever password was passed in.
// See: http://golang.org/misc/dashboard/app/build/key.go
dp := Password{
Value: password,
}
if _, err := datastore.Put(c, k, &dp); err != nil {
return false
}
return true
}
return p.Value == password
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment