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; }
internal void AddString(string data) { this._hash = HashAlgorithm.GetHash(data, this._hash); }
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)); }