summary refs log tree commit diff stats
path: root/auth
diff options
context:
space:
mode:
Diffstat (limited to 'auth')
-rw-r--r--auth/checkpass.go14
-rw-r--r--auth/checkpass_test.go40
-rw-r--r--auth/genid.go14
-rw-r--r--auth/hashpass.go13
-rw-r--r--auth/hashpass_test.go34
5 files changed, 0 insertions, 115 deletions
diff --git a/auth/checkpass.go b/auth/checkpass.go
deleted file mode 100644
index 64e3c9f..0000000
--- a/auth/checkpass.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package auth
-
-import (
-	"golang.org/x/crypto/bcrypt"
-)
-
-// checkPass takes a string and hash as input and returns an error. If
-// the error is not nil then the consider the password wrong. We're
-// returning error instead of a bool so that we can print failed
-// logins to log and logging shouldn't happen here.
-func checkPass(password, hash string) error {
-	err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
-	return err
-}
diff --git a/auth/checkpass_test.go b/auth/checkpass_test.go
deleted file mode 100644
index c8afaee..0000000
--- a/auth/checkpass_test.go
+++ /dev/null
@@ -1,40 +0,0 @@
-package auth
-
-import "testing"
-
-// TestCheckPass tests the checkPass function.
-func TestCheckPass(t *testing.T) {
-	var err error
-	passhash := make(map[string]string)
-
-	// First we check with static values, these should always pass.
-	passhash["ter4cQ=="] = "$2a$10$ANkaNEFFQ4zxDwTwvAUfoOCqpVIdgtPFopFOTMSrFy39WkaMAYLIC"
-	passhash["G29J6A=="] = "$2a$10$1oH1PyhncIHcHJWbLt3Gv.OjClUoFoaEDaFpQ9E9atfRbIrVxsbwm"
-	passhash["Z1S/kQ=="] = "$2a$10$fZ05kKmb7bh4vBLebpK1u.3bUNQ6eeX5ghT/GZaekgS.5bx4.Ru1e"
-	passhash["J861dQ=="] = "$2a$10$nXb6Btn6n3AWMAUkDh9bFObvQw5V9FLKhfX.E1EzRWgVDuqIp99u2"
-
-	// We also check with values generated with hashPass, this may
-	// fail if hashPass itself fails in that case it's not
-	// checkPass error so the test shouldn't fail but warning
-	// should be sent. We use genID func to generate random inputs
-	// for this test.
-	for i := 1; i <= 4; i++ {
-		p := genID(8)
-		passhash[p], err = hashPass(p)
-		if err != nil {
-			t.Log("hashPass func failed")
-		}
-	}
-
-	// We test the checkPass func by ranging over all values of
-	// passhash. We assume that hashPass func returns correct
-	// hashes.
-	for p, h := range passhash {
-		err = checkPass(p, h)
-		if err != nil {
-			t.Errorf("password: %s, hash: %s didn't match.",
-				p, h)
-		}
-	}
-
-}
diff --git a/auth/genid.go b/auth/genid.go
deleted file mode 100644
index fea7ac9..0000000
--- a/auth/genid.go
+++ /dev/null
@@ -1,14 +0,0 @@
-package auth
-
-import (
-	"crypto/rand"
-	"encoding/base64"
-)
-
-// genID generates a random id string of length n. Don't forget to
-// seed the random number generator otherwise it won't be random.
-func genID(n int) string {
-	b := make([]byte, n/2)
-	rand.Read(b)
-	return base64.StdEncoding.EncodeToString(b)
-}
diff --git a/auth/hashpass.go b/auth/hashpass.go
deleted file mode 100644
index 4e5041a..0000000
--- a/auth/hashpass.go
+++ /dev/null
@@ -1,13 +0,0 @@
-package auth
-
-import (
-	"golang.org/x/crypto/bcrypt"
-)
-
-// hashPass takes a string as input and returns the hash of the
-// password.
-func hashPass(password string) (string, error) {
-	// 10 is the default cost.
-	bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10)
-	return string(bytes), err
-}
diff --git a/auth/hashpass_test.go b/auth/hashpass_test.go
deleted file mode 100644
index 7ea9480..0000000
--- a/auth/hashpass_test.go
+++ /dev/null
@@ -1,34 +0,0 @@
-package auth
-
-import "testing"
-
-// TestHashPass tests the checkPass function.
-func TestHashPass(t *testing.T) {
-	var err error
-	passhash := make(map[string]string)
-
-	// We generate random hashes with hashPass, random string is
-	// generate by genID func.
-	for i := 1; i <= 8; i++ {
-		p := genID(8)
-		passhash[p], err = hashPass(p)
-
-		// Here we test if the hashPass func runs sucessfully.
-		if err != nil {
-			t.Errorf("hashPass func failed for password: %s",
-				p)
-		}
-	}
-
-	// Here we are testing if the hashPass func returns correct
-	// hashes. We assume that checkPass func returns correct
-	// values.
-	for p, h := range passhash {
-		err = checkPass(p, h)
-		if err != nil {
-			t.Errorf("password: %s, hash: %s didn't match.",
-				p, h)
-		}
-	}
-
-}