aboutsummaryrefslogtreecommitdiff
path: root/backend/hashing/hash.go
diff options
context:
space:
mode:
authorRyan Mehri <[email protected]>2020-05-15 17:58:09 -0600
committerRyan Mehri <[email protected]>2020-05-15 17:58:09 -0600
commit5d037e8297a192996b7281af0ca761c160aaed30 (patch)
tree68a21642cfb9396e734f16e8d636af3efdee49a0 /backend/hashing/hash.go
parentMerge pull request #24 from jackyzha0/update-readme (diff)
downloadctrl-v-5d037e8297a192996b7281af0ca761c160aaed30.tar.xz
ctrl-v-5d037e8297a192996b7281af0ca761c160aaed30.zip
Add encryption to content when password is specified
Diffstat (limited to 'backend/hashing/hash.go')
-rw-r--r--backend/hashing/hash.go41
1 files changed, 0 insertions, 41 deletions
diff --git a/backend/hashing/hash.go b/backend/hashing/hash.go
deleted file mode 100644
index e944fbe..0000000
--- a/backend/hashing/hash.go
+++ /dev/null
@@ -1,41 +0,0 @@
-package hashing
-
-import (
- "crypto/md5"
- "encoding/hex"
- "golang.org/x/crypto/bcrypt"
- "math/big"
- "time"
-)
-
-const UrlLength = 7
-
-// GenerateURI creates a unique identifier for a paste based on ip and timestamp
-func GenerateURI(ip string) string {
- timeStamp := time.Now().String()
- return hashString(ip + timeStamp)[:UrlLength]
-}
-
-// hashes using MD5 and then converts to base 62
-func hashString(text string) string {
- hash := md5.Sum([]byte(text))
- hexStr := hex.EncodeToString(hash[:])
-
- bi := big.NewInt(0)
- bi.SetString(hexStr, 16)
- return bi.Text(62)
-}
-
-func HashPassword(password string) (string, error) {
- hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
- return string(hashedPassword), err
-}
-
-func PasswordsEqual(dbPassword, parsedPassword string) bool {
- dbPassBytes := []byte(dbPassword)
- parsedPassBytes := []byte(parsedPassword)
- compErr := bcrypt.CompareHashAndPassword(dbPassBytes, parsedPassBytes)
-
- // if comparison error, the given password is not valid
- return compErr == nil
-} \ No newline at end of file