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); } } }