Created
May 2, 2012 04:06
-
-
Save thebigbad/2573539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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