summaryrefslogtreecommitdiff
path: root/app/utilities.go
diff options
context:
space:
mode:
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)