summaryrefslogtreecommitdiff
path: root/app/utilities.go
diff options
context:
space:
mode:
authorHorus_Arch2015-02-22 17:20:18 +0100
committerHorus_Arch2015-02-22 17:20:18 +0100
commit00b28812fb5ab68156ead5b45b66740a4d5ca688 (patch)
tree1db4545d5925943a1a761226ac378bb14d9204b7 /app/utilities.go
parentbdb2d33a30765a25be3dd8c82b92517efa00dda8 (diff)
downloadstatuspage-00b28812fb5ab68156ead5b45b66740a4d5ca688.tar.gz
Unit tests are now triggered by build tags.
Diffstat (limited to 'app/utilities.go')
-rw-r--r--app/utilities.go21
1 files changed, 20 insertions, 1 deletions
diff --git a/app/utilities.go b/app/utilities.go
index 3ec1b60..a3c3617 100644
--- a/app/utilities.go
+++ b/app/utilities.go
@@ -4,6 +4,7 @@ import (
"bytes"
"crypto/md5"
"encoding/gob"
+ "errors"
"fmt"
"github.com/garyburd/redigo/redis"
"golang.org/x/crypto/bcrypt"
@@ -16,6 +17,21 @@ import (
"time"
)
+/*
+type errorString struct {
+ s string
+}
+
+func (e *errorString) Error() string {
+ return e.s
+}
+
+// New returns an error that formats as the given text.
+func New(text string) error {
+ return &errorString{text}
+}
+*/
+
// Returns headers as map and the content of a webpage as string
func HttpGet(url string) (*http.Response, string, error) {
r, err := http.Get(url)
@@ -78,7 +94,7 @@ func newPool() *redis.Pool {
// Hashs password with bcrypt and returns the string
func HashPassword(password string) (string, error) {
if password == "" {
- return "", nil
+ return "", errors.New("Empty password.")
}
p := []byte(password)
hash, err := bcrypt.GenerateFromPassword(p, 10)
@@ -90,6 +106,9 @@ func HashPassword(password string) (string, error) {
// Verify password and hash
func VerifyPassword(password, hash string) bool {
+ if hash == "" || password == "" {
+ return false
+ }
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
if err != nil {
log.Printf("%s \n", err)