Browse Source

auth work

reid 2 năm trước cách đây
mục cha
commit
7c01339244
2 tập tin đã thay đổi với 6 bổ sung5 xóa
  1. 5 5
      auth/auth.go
  2. 1 0
      ws/ws.go

+ 5 - 5
auth/auth.go

@@ -7,7 +7,7 @@ package auth
 
 import (
 	"crypto/rand"
-	"crypto/sha256"
+	"crypto/sha512"
 	"encoding/base64"
 	"encoding/hex"
 	"encoding/json"
@@ -70,7 +70,7 @@ func WsAuthCheck(conn *websocket.Conn) bool {
 func AddToAuthMap(conn *websocket.Conn, token map[string]string, authed bool) error {
 	tokenStr := token["token"]
 	tokenId := token["id"]
-	hashed := sha256.Sum256([]byte(tokenStr))
+	hashed := sha512.Sum512([]byte(tokenStr))
 	hash := hex.EncodeToString(hashed[:])
 	if authed {
 		AuthenticatedClients.Lock()
@@ -121,7 +121,7 @@ func CheckToken(token map[string]string, conn *websocket.Conn, r *http.Request,
 			ip, _, _ = net.SplitHostPort(r.RemoteAddr)
 		}
 		userAgent := r.Header.Get("User-Agent")
-		hashed := sha256.Sum256([]byte(token["token"]))
+		hashed := sha512.Sum512([]byte(token["token"]))
 		hash := hex.EncodeToString(hashed[:])
 		// you in auth map?
 		if WsIsAuthenticated(conn, hash) {
@@ -269,12 +269,12 @@ func KeyfileDecrypt(encryptedText string, key string) (map[string]string, error)
 	return contents, nil
 }
 
-// salted sha256
+// salted sha512
 func Hasher(password string) string {
 	conf := config.Conf()
 	salt := conf.Salt
 	toHash := salt + password
-	res := sha256.Sum256([]byte(toHash))
+	res := sha512.Sum512([]byte(toHash))
 	return hex.EncodeToString(res[:])
 }
 

+ 1 - 0
ws/ws.go

@@ -161,6 +161,7 @@ func WsHandler(w http.ResponseWriter, r *http.Request) {
 // validate password and add to auth session map
 func loginHandler(conn *websocket.Conn, msg []byte, payload structs.WsPayload) error {
 	config.Logger.Info("Login")
+	// lets do this ugly shit to get the password out
 	var msgMap map[string]interface{}
 	err := json.Unmarshal(msg, &msgMap)
 	if err != nil {