Menu

Sunday, November 21, 2010

How To get User ID & Password text file?

Step1. Import "IO" package.
using System.IO;

Step2.Declarer Four String Variables.
string username = "";
string password = "";

string str1 = "";
string str2 = "";


Step3.Write Two StreamReader's Objects their Constructors & Path of the .txt Files
StreamReader sr1 = new StreamReader(@"c:\Foldername\\ID.txt");
StreamReader sr2 = new StreamReader(@"c:\Foldername\\Password.txt");

Step4.Write While Loop to Read ID & Password Files's Data.
while ((str1 = sr1.ReadLine()) != null)
{
username=str1;
}

while ((str2 = sr2.ReadLine()) != null)
{
password=str2;
}


Step5.Write "IF" Condition To check is ID & Password are correct.
if(txtUserID.Text==username && txtPasswoed.Text==password)
{
MessageBox.Show("Welcome");
}
else
{
MessageBox.Show("Invalid UserID or Password");
}