<commit_before>package authentification

import (
	"time"
	"../tools"
	"net/http"
	"github.com/gin-gonic/gin"
)

/****
* http://localhost:8080/login/
* curl -i -X POST -d '{"login":"<name>","pwd":"<<PASSWORD>>"}' http://localhost:8080/authentification/
****/

func Login(c *gin.Context) {

	var json tools.Login_form
	
	if c.BindJSON(&json) == nil {
		if u, ok := tools.Users[json.Login]; ok {
			if tools.Crypt_sha256(json.Pwd) == u.Password {
				
				u.Last_connection = time.Now()
				u.Token =  tools.Crypt_sha256(u.Login+"-"+u.Last_connection.Format("2006-01-02 15:04:05"))
				
				tools.Connected_users[u.Id] = u
				tools.Users_id[u.Id]
				tools.Users[u.Login]
				
				c.JSON(http.StatusOK, gin.H{
					"user_id": u.Id,
					"user_name": u.Login,
					"token": u.Token,
					"msg": "you are logged in",
				})
				return
			}
			
			c.JSON(http.StatusForbidden, gin.H{
				"msg": "the login or the pwd are invalid",
			})
			return
		}
		
		c.JSON(http.StatusForbidden, gin.H{
			"msg": "the login or the pwd are invalid",
		})
		return
	}
	c.JSON(http.StatusBadRequest, gin.H{
		"msg": "no login or pwd found in params of the query",
	})
}<commit_msg>bug fix on auth and finding maps<commit_after>package authentification

import (
	"time"
	"../tools"
	"net/http"
	"github.com/gin-gonic/gin"
)

/****
* http://localhost:8080/login/
* curl -i -X POST -d '{"login":"<name>","pwd":"<<PASSWORD>>"}' http://localhost:8080/authentification/
****/

func Login(c *gin.Context) {

	var json tools.Login_form
	
	if c.BindJSON(&json) == nil {
		if u, ok := tools.Users[json.Login]; ok {
			if tools.Crypt_sha256(json.Pwd) == u.Password {
				
				u.Last_connection = time.Now()
				u.Token =  tools.Crypt_sha256(u.Login+"-"+u.Last_connection.Format("2006-01-02 15:04:05"))
				
				tools.Connected_users[u.Id] = u
				tools.Users_id[u.Id] = u
				tools.Users[u.Login] = u
				
				c.JSON(http.StatusOK, gin.H{
					"user_id": u.Id,
					"user_name": u.Login,
					"token": u.Token,
					"msg": "you are logged in",
				})
				return
			}
			
			c.JSON(http.StatusForbidden, gin.H{
				"msg": "the login or the pwd are invalid",
			})
			return
		}
		
		c.JSON(http.StatusForbidden, gin.H{
			"msg": "the login or the pwd are invalid",
		})
		return
	}
	c.JSON(http.StatusBadRequest, gin.H{
		"msg": "no login or pwd found in params of the query",
	})
}
{'fraction_non_alphanumeric': 0.18189545261368467, 'fraction_numerical': 0.02379940501487463, 'mean_word_length': 2.890909090909091, 'pattern_counts': {'":': 18, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5874152', 'n_tokens_mistral': 1131, 'n_tokens_neox': 921, 'n_words': 188}