/// <summary> /// Partendo dalla password in chiaro originale, genera il salt e l'hash /// ed imposta automaticamente le proprietà HashPass e SaltPass. /// </summary> /// <param name="password">La password originale in chiaro</param> public void ImpostaPasswordDaOriginale(string password) { // Genera il salt casuale string salt = HashUtil.GeneraSalt(); // Genera l'hash della password concatenata con il salt string hash = HashUtil.GeneraSHA256(password + salt); HashPass = hash; SaltPass = salt; }
public IUtente ValidaCredenziali(string username, string pass) { IUtente outputUtente = null; using (SQLiteCommand cmd = new SQLiteCommand("SELECT * FROM utenti WHERE username = @Username", _connection)) { cmd.Prepare(); cmd.Parameters.AddWithValue("@Username", username); using (SQLiteDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { outputUtente = Utente.ConvertiRigaInUtente(reader); } } } // Controllo che l'utente esista e la password corrisponda if (outputUtente == null) { return(null); } else { // Controllo che la password corrisponda string hashPrevisto = HashUtil.GeneraSHA256(pass + outputUtente.SaltPass); if (hashPrevisto == outputUtente.HashPass) { return(outputUtente); } else { return(null); } } }