Ejemplo n.º 1
0
        public IActionResult Login()
        {
            string username      = Request.Form["username"];
            string plainPassword = Request.Form["password"];

            string hash = _hashAlgorithm.GetHash(plainPassword);

            if (_communicationWithDB.Login(username, hash))
            {
                _appConfig.Login(username);

                var userClaims = new List <Claim>()
                {
                    new Claim(ClaimTypes.Name, username)
                };
                var userIdentity  = new ClaimsIdentity(userClaims, "user identity");
                var userPrincipal = new ClaimsPrincipal(new[] { userIdentity });
                HttpContext.SignInAsync(userPrincipal);

                return(Redirect("/chat"));
            }
            else
            {
                Response.Cookies.Append("invalid-login", "true");
                return(Redirect("/login"));
            }
        }
        /// <summary>
        /// Assigne à des propriétés, des hachages d'identifiants de connexion.
        /// </summary>
        /// <param name="_username">Nom d'utilisateur</param>
        /// <param name="_password">Mot de passe</param>
        private static void SetUsnAndPwdHash(string _username, string _password)
        {
            string username = _username;
            string password = _password;

            // Obtient le hachage des identifiants de connexion.
            byte[] hashedUsername = HashAlgorithm.GetHash(Encoding.ASCII.GetBytes(username));
            byte[] hashedPassword = HashAlgorithm.GetHash(Encoding.ASCII.GetBytes(password));

            // Assigne à des propriétés, les valeurs obtenues.
            UsernameHashed = hashedUsername;
            PasswordHashed = hashedPassword;
        }
Ejemplo n.º 3
0
 internal void AddString(string data)
 {
     this._hash = HashAlgorithm.GetHash(data, this._hash);
 }
Ejemplo n.º 4
0
 internal static ulong GetHash(string data)
 {
     return(HashAlgorithm.GetHash(data, 0UL));
 }
        public static string GetHash(string text)
        {
            HashAlgorithm alg = HashAlgorithm.Create();

            return(alg.GetHash(text));
        }