-1

How can I check if the contents of a file and some words that were inputted are the same? I want to make some sort of activation system, where it will check if the contents are the same as the input.

Here's what I want to do:

using System.Collections.Generic;
using System;
using System.IO;

namespace Example {
  public class Example() {
    string input = Console.ReadLine();
    if (input == File(@"/prodkey.txt") {
      //code
    }
  }
}
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Marko2155
  • 3
  • 3
  • 1
    The exact same, like a password? Or do you mean like search where it is looking to find all of the words somewhere in the document? As a sentence, or with the words appearing in any order> – Dave S Feb 09 '23 at 18:04
  • compare checksums? – Mikael Feb 09 '23 at 18:05
  • 1
    Does this answer your question? [How to compare 2 files fast using .NET?](https://stackoverflow.com/questions/1358510/how-to-compare-2-files-fast-using-net) – SiKing Feb 09 '23 at 18:06
  • Your title says "two files" but your question and code say "words that were inputted" -- which is it? Please edit your question to add more information. – Dave S Feb 09 '23 at 18:06
  • @DaveS Like a password. – Marko2155 Feb 09 '23 at 21:14
  • @Dave S And yes, as soon as i posted it, i found out that it said "two files" instead of "words that were inputted. I forgot to fix it. – Marko2155 Feb 09 '23 at 21:16

1 Answers1

2

You can use File.ReadAllText(filePath) to get the contents of a text file, and then compare them using the == operator, or the string.Equals method (which provides for case-insensitive comparison):

string input = Console.ReadLine();
string fileContent = File.ReadAllText(@"/prodkey.txt");

if (input == fileContent) 
{
  
}

// Or, for case-insensitive comparison:
if (input.Equals(fileContent, StringComparison.OrdinalIgnoreCase))
{
  
}
Rufus L
  • 36,127
  • 5
  • 30
  • 43