console shape


console shape Code


using
System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication8

{

class Program

{

static void Main()

{

Console.WriteLine("Shape 1:");







for (int i = 0; i < 7; i++)

{

for (int j = 0; j < 4; j++)

{

if ((((i + j) > 2) && (i <= 3)) || ((i > 3) && (j >= i - 3)))

{

Console.Write("*");

}

else

{

Console.Write(" ");

}

}
Console.WriteLine();

} Console.WriteLine("\nShape 2:");

for (int i = 0; i < 7; i++)

{

for (int j = 0; j < 7; j++)

{

if (((((i + j) > 2) && (j < 4)) || ((j - i <= 3) && (j >= 4))) && (i <= 3))

{

Console.Write("*");

}

else if ((i > 3) && (((j >= i - 3) && (j <= 3)) || ((j > 3) && (i + j < 10))))

{

Console.Write("*");

}

else

{

Console.Write(" ");

}

}
Console.WriteLine();

} Console.ReadLine();

}

}

}

screenshot


-----------------------------------------------------------------------------------------------------------

by: Pankaj Sharna

file download

File Download in C# Code


System.Net.WebClient downloader = new System.Net.WebClient();

downloader.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.Revalidate);

downloader.DownloadFileAsync(new Uri("http://www.domainName.com/apple.zip"), "d:\\newApple.zip");
---------------------------------------------------------------------------------------------------------------------------------------

by: VidyaGyan

send email

send email via C# .Net


System.Net.Mail.
MailMessage email = new System.Net.Mail.MailMessage();

email.To.Add("xyz@gmail.com"); //reciever email

email.From = new System.Net.Mail.MailAddress("myEmail@gmail.com", "your Name"); //sender email & display Name

email.Subject = "My First C# mail"; //message subject

email.Body = "i am testing my first e-mail program."; //message body

System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com"); //email server name

smtp.EnableSsl = true; //set false if your email server not using Ssl.

smtp.Credentials = new System.Net.NetworkCredential("myEmail@gmail.com", "password");//sender email & Password

smtp.Send(email);

by: Pankaj Sharma


event log


event log C#  .net  Project Logs


using
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Data.OleDb;
using System.Data;

namespace Logs

{

class Program

{



static void Main(string[] args)

{

OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Directory.GetCurrentDirectory() + "/db1.mdb;");

login:

Console.BackgroundColor = ConsoleColor.Black;

Console.ForegroundColor = ConsoleColor.White;

Console.Write("UserName:");

string userName = Console.ReadLine();

Console.Write("password:");

string p ="";

while (true)

{

ConsoleKeyInfo ki = new ConsoleKeyInfo();

ki=Console.ReadKey();



if (ki.Key==ConsoleKey.Enter)

{

break;

}

p +=ki.KeyChar.ToString();

Console.Write(Convert.ToChar(8));

Console.Write("*");

}

Console.WriteLine();


OleDbDataAdapter od = new OleDbDataAdapter("select * from t1 where username='" + userName + "' AND password='" + p + "'", con);

DataTable dt = new DataTable();

od.Fill(dt);

if (dt.Rows.Count != 1)

{

Console.BackgroundColor = ConsoleColor.Red;

Console.ForegroundColor = ConsoleColor.White;

Console.WriteLine("Invalid userName or Password");

Console.WriteLine();

Console.WriteLine();

goto login;

}

if (dt.Rows[0][4].ToString() == "Admin")

{

top:

Console.ResetColor();

Console.BackgroundColor = ConsoleColor.Red;

Console.ForegroundColor = ConsoleColor.White;

Console.Title = "<<<< Welcome To secure world >>>> Administrator";

Console.WriteLine("**** Select a option ****");

Console.WriteLine("1.Write Logs");

Console.WriteLine("2.Read Logs");

Console.WriteLine("3.Settings");

Console.WriteLine("4.Exit");

Console.Write("enter your choice:");

string choice;

try

{

choice =
Console.ReadLine();

if (!(choice == "1" || choice == "2" || choice == "3" || choice == "4"))

{

Console.Clear();

Console.WriteLine("*** invalid f choice ***");

goto top;

}

}

catch

{

Console.Clear();

Console.WriteLine("*** invalid choice ***");

goto top;

}

 

if (choice == "1")

{

for (int d = 0; d < 8; d++)

{

try

{

Console.BackgroundColor = ConsoleColor.Blue;

EventLog eventLog1 = new EventLog();

if (d == 0)

{

eventLog1.Log =
"System";

}

else if (d == 1)

{

eventLog1.Log =
"Windows PowerShell";

}

else if (d == 2)

{

eventLog1.Log =
"Application";

}

else if (d == 3)

{

eventLog1.Log =
"HardwareEvents";

}

else if (d == 4)

{

eventLog1.Log =
"Internet Explorer";

}

else if (d == 5)

{

eventLog1.Log =
"Key Management Service";

}

else if (d == 6)

{

eventLog1.Log =
"Media Center";

}

else if (d == 7)

{

eventLog1.Log =
"Security";

}

eventLog1.MachineName =
Environment.MachineName;

Console.WriteLine();

Console.WriteLine("Current MachineName: " + Environment.MachineName);

Console.WriteLine("Requesting for "+eventLog1.Log+"Logs...");

Thread.Sleep(1000);

Console.WriteLine(" Logs Found(" + eventLog1.Entries.Count + ")");

Console.BackgroundColor = ConsoleColor.Magenta;

Console.WriteLine("Waiting for system-Response...");

Thread.Sleep(1000);

foreach (EventLogEntry entry in eventLog1.Entries)//to create directory

{

if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName + "\\" + eventLog1.Log + "\\" + entry.EntryType.ToString()))

{

Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName + "\\" + eventLog1.Log + "\\" + entry.EntryType.ToString());

}

if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName + "\\" + eventLog1.Log + "\\" + entry.EntryType.ToString() + "\\" + entry.Source))

{

Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName + "\\" + eventLog1.Log + "\\" + entry.EntryType.ToString() + "\\" + entry.Source);

}

if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName + "\\" + eventLog1.Log + "\\" + entry.EntryType.ToString() + "\\" + entry.Source + "\\" + entry.TimeWritten.ToLongDateString()))

{

// string sp = AppDomain.CurrentDomain.BaseDirectory + "\\"+Environment.MachineName+"\\" + entry.EntryType.ToString() + "\\" + entry.Source + "\\" + entry.TimeWritten.ToLongDateString();

Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName + "\\" + eventLog1.Log + "\\" + entry.EntryType.ToString() + "\\" + entry.Source + "\\" + entry.TimeWritten.ToLongDateString());

}

if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName + "\\" + eventLog1.Log + "\\" + entry.EntryType.ToString() + "\\" + entry.Source + "\\" + entry.TimeWritten.ToLongDateString() + "\\" + entry.Index.ToString() + ".log"))

{

string s1 = entry.Message, s2 = "";

Console.ResetColor();

Console.ForegroundColor = ConsoleColor.Gray;

Console.Write("\nLog Index=" + entry.Index + " Encripting...");

for (int i = 0; i < s1.Length; i++)

{

int value = Convert.ToInt32(s1[i]) / 16;

int remaim = Convert.ToInt32(s1[i]) % 16;

if (remaim > 9)

{

if (remaim == 10)

{

s2 += value.ToString() +
"A";

}

else if (remaim == 11)

{

s2 += value.ToString() +
"B";

}

else if (remaim == 12)

{

s2 += value.ToString() +
"C";

}

else if (remaim == 13)

{

s2 += value.ToString() +
"D";

}

else if (remaim == 14)

{

s2 += value.ToString() +
"E";

}

else if (remaim == 15)

{

s2 += value.ToString() +
"F";

}

}

else

{

s2 += value.ToString() + remaim.ToString();

}

s2 +=
" ";

}

File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName + "\\" + eventLog1.Log + "\\" + entry.EntryType.ToString() + "\\" + entry.Source + "\\" + entry.TimeWritten.ToLongDateString() + "\\" + entry.Index.ToString() + ".log", s2);

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.Write(" Successed");

}

}

}

catch { }

}

}

else if (choice == "2")

{

Console.ResetColor();

Console.Clear();

Console.ForegroundColor = ConsoleColor.DarkRed;

string[] EntryTypeList = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName);

Console.WriteLine("**** Select logType ****");

for (int i = 0; i < EntryTypeList.Length; i++)

{

DirectoryInfo di = new DirectoryInfo(EntryTypeList[i]);

Console.WriteLine(i + 1 + "." + di.Name);

}

Console.Write("enter your choice:");

choice = Console.ReadLine();

Console.Clear();

Console.WriteLine("**** Select LogProvider ****");

string[] logen = Directory.GetDirectories(EntryTypeList[int.Parse(choice) - 1]);

for (int i = 0; i < logen.Length; i++)

{

DirectoryInfo di = new DirectoryInfo(logen[i]);

Console.WriteLine(i + 1 + "." + di.Name);

}

Console.Write("enter your choice:");

choice = Console.ReadLine();

Console.Clear();

Console.WriteLine("**** Select LogProvider ****");

string[] logSource = Directory.GetDirectories(logen[int.Parse(choice) - 1]);

for (int i = 0; i < logSource.Length; i++)

{

DirectoryInfo di = new DirectoryInfo(logSource[i]);

Console.WriteLine(i + 1 + "." + di.Name);

}

Console.Write("enter your choice:");

choice = Console.ReadLine();

Console.Clear();

Console.WriteLine("**** Select Log-Index ****");

Console.WriteLine("index\t\tDate");

string[] logDate = Directory.GetDirectories(logSource[int.Parse(choice) - 1]);

Console.ForegroundColor = ConsoleColor.Red;

for (int i = 0; i < logDate.Length; i++)

{

DirectoryInfo di = new DirectoryInfo(logDate[i]);

string[] logIndex = Directory.GetFiles(logDate[i]);

for (int j = 0; j < logIndex.Length; j++)

{

FileInfo fi = new FileInfo(logIndex[j]);

Console.WriteLine(fi.Name.Remove(fi.Name.IndexOf(".log")) + "\t" + di.Name);

}

}

Console.Write("enter Index-Number:");

string fileName = Console.ReadLine();

for (int i = 0; i < logDate.Length; i++)

{

if (File.Exists(logDate[i] + "\\" + fileName + ".log"))

{

string FileData = File.ReadAllText(logDate[i] + "\\" + fileName + ".log");

string getedData = "";

int count = 0;

for (int r = 0; r < FileData.Length; r++)

{

if (FileData[r].ToString() == " ")

{

count++;

}

}

string[] w_list = new string[count];

int w_index = 0;

for (int r = 0; r < FileData.Length; r++)

{

if (FileData[r].ToString() == " ")

{

w_index++;

}

else

{

w_list[w_index] += FileData[r].ToString(); ;

}

}

for (int ii = 0; ii < w_list.Length; ii++)

{

int w = 0;

if (w_list[ii][w_list[ii].Length - 1].ToString() == "A")

{

w = 10;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "B")

{

w = 11;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "C")

{

w = 12;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "D")

{

w = 13;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "E")

{

w = 14;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "F")

{

w = 15;

}

else

{

w =
int.Parse(w_list[ii][w_list[ii].Length - 1].ToString());

}

string temp = "";

for (int iii = 0; iii < w_list[ii].Length - 1; iii++)

{

temp += w_list[ii][iii].ToString();

}

getedData +=
Convert.ToChar((int.Parse(temp) * 16) + w).ToString();

}

Console.ResetColor();

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.WriteLine(getedData);

break;

}

}

 

}

else if (choice == "3")

{

Console.WriteLine();

Console.ResetColor();

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("1.Add User");

Console.WriteLine("2.Delele User");

Console.WriteLine("3.change UserPermissions");

Console.WriteLine("4.Change Password");

ConsoleKeyInfo ki = new ConsoleKeyInfo();

ki= Console.ReadKey();

if (ki.KeyChar.ToString() == "1")

{

Console.Clear();

Console.Write("enter new UserName:");

string Newuser=Console.ReadLine();

Console.Write("enter new Pssword:");

string newPassword = "";

while (true)

{

ConsoleKeyInfo kii = new ConsoleKeyInfo();

kii = Console.ReadKey();

if (kii.Key == ConsoleKey.Enter)

{

break;

}

newPassword += kii.KeyChar.ToString();

Console.Write(Convert.ToChar(8));

Console.Write("*");

}

Console.WriteLine();

Console.Write("permissions for:");

string permission = Console.ReadLine();

Console.WriteLine();

Console.Write("userType(Admin/user):");

string usertype= Console.ReadLine();

try

{

OleDbCommand comIn = new OleDbCommand("insert into t1 values('" + Newuser + "','" + newPassword + "','" + permission + "','All','" + usertype + "')", con);

con.Open();

comIn.ExecuteNonQuery();

con.Close();

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.WriteLine(" <<<user has been Added>>>");

Console.WriteLine();

}

catch (Exception ei)

{

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.WriteLine(" <<<"+ei.Message+">>>");

Console.WriteLine();

}

}

else if (ki.KeyChar.ToString() == "2")

{

Console.Clear();

Console.WriteLine();

Console.Write("Enter UserName To Delete:");

string user = Console.ReadLine();

try

{

OleDbCommand comDel = new OleDbCommand("delete from t1 where username='" + user + "'", con);

con.Open();

comDel.ExecuteNonQuery();

con.Close();

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.WriteLine(" <<<user has been Deleted>>>");

Console.WriteLine();

}

catch (Exception ei)

{

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.WriteLine(" <<<" + ei.Message + ">>>");

Console.WriteLine();

}

}

else if (ki.KeyChar.ToString() == "3")

{

Console.Clear();

Console.WriteLine();

Console.Write("Enter UserName:");

string user = Console.ReadLine();

Console.WriteLine();

Console.Write("permissions for:");

string permission = Console.ReadLine();

Console.WriteLine();

Console.Write("userType(Admin/user):");

string usertype = Console.ReadLine();

try

{

OleDbCommand comUp = new OleDbCommand("update t1 set permissions='" + permission + "',UserType='" + usertype + "' where username='" + user + "'", con);

con.Open();

comUp.ExecuteNonQuery();

con.Close();

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.WriteLine(" <<<user detail has been changed>>>");

Console.WriteLine();

}

catch (Exception ei)

{

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.WriteLine(" <<<" + ei.Message + ">>>");

Console.WriteLine();

}

}

else if (ki.KeyChar.ToString() == "4")

{

Console.Clear();

Console.Write("enter your Current Password:");

string currentPassword = "";

while (true)

{

ConsoleKeyInfo kii = new ConsoleKeyInfo();

kii = Console.ReadKey();

if (kii.Key == ConsoleKey.Enter)

{

break;

}

currentPassword += kii.KeyChar.ToString();

Console.Write(Convert.ToChar(8));

Console.Write("*");

}

Console.WriteLine();

Console.Write("enter your new Password:");

string newPassword = "";

while (true)

{

ConsoleKeyInfo kii = new ConsoleKeyInfo();

kii = Console.ReadKey();

if (kii.Key == ConsoleKey.Enter)

{

break;

}

newPassword += kii.KeyChar.ToString();

Console.Write(Convert.ToChar(8));

Console.Write("*");

}

Console.WriteLine();

Console.Write("enter your new Password:");

string confPassword = "";

while (true)

{

ConsoleKeyInfo kii = new ConsoleKeyInfo();

kii = Console.ReadKey();

if (kii.Key == ConsoleKey.Enter)

{

break;

}

confPassword += kii.KeyChar.ToString();

Console.Write(Convert.ToChar(8));

Console.Write("*");

}

if (newPassword == confPassword)

{

if (currentPassword == p)

{

try

{

OleDbCommand commUp = new OleDbCommand("update t1 set password='" + newPassword + "' where username='" + userName + "'", con);

con.Open();

commUp.ExecuteNonQuery();

con.Close();

Console.WriteLine("Password changed");

}

catch (Exception ei)

{

Console.WriteLine(ei.Message);

}

}

else

{

Console.WriteLine("Invalid Password");

}

}

else

{

Console.WriteLine("password misMatch");

}

}



}

else if (choice == "4")

{

Console.ResetColor();

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("Closing application...");

Thread.Sleep(1000);

Thread.CurrentThread.Abort();

}

 

Console.ReadLine();

Console.Clear();

Console.ResetColor();

goto top;

}

//if userlogedIn

else if (dt.Rows[0][4].ToString() == "user")

{

top:

Console.ResetColor();

Console.BackgroundColor = ConsoleColor.Red;

Console.ForegroundColor = ConsoleColor.White;

Console.Title = "<<<< Welcome To secure world >>>> User";

Console.WriteLine("**** Select a option ****");

Console.WriteLine("1.Read Logs");

Console.WriteLine("2.Settings");

Console.WriteLine("3.Exit");

Console.Write("enter your choice:");

string choice;

try

{

choice =
Console.ReadLine();

if (!(choice == "1" || choice == "2"|| choice == "3"))

{

Console.Clear();

Console.WriteLine("*** invalid f choice ***");

goto top;

}

}

catch

{

Console.Clear();

Console.WriteLine("*** invalid choice ***");

goto top;

}

if (choice == "1")

{

Console.ResetColor();

Console.Clear();

Console.ForegroundColor = ConsoleColor.DarkRed;



string str = dt.Rows[0][2].ToString();



string[] EntryTypeList = Directory.GetDirectories(AppDomain.CurrentDomain.BaseDirectory + "\\" + Environment.MachineName);



Console.WriteLine("**** Select logType ****");

for (int i = 0; i < EntryTypeList.Length; i++)

{

DirectoryInfo di = new DirectoryInfo(EntryTypeList[i]);

if (str.IndexOf(di.Name) != -1)

{

Console.WriteLine(i + 1 + "." + di.Name);

}

}

Console.Write("enter your choice:");

choice = Console.ReadLine();

Console.Clear();

Console.WriteLine("**** Select LogProvider ****");

string[] logen = Directory.GetDirectories(EntryTypeList[int.Parse(choice) - 1]);

for (int i = 0; i < logen.Length; i++)

{

DirectoryInfo di = new DirectoryInfo(logen[i]);

Console.WriteLine(i + 1 + "." + di.Name);

}

Console.Write("enter your choice:");

choice = Console.ReadLine();

Console.Clear();

Console.WriteLine("**** Select LogProvider ****");

string[] logSource = Directory.GetDirectories(logen[int.Parse(choice) - 1]);

for (int i = 0; i < logSource.Length; i++)

{

DirectoryInfo di = new DirectoryInfo(logSource[i]);

Console.WriteLine(i + 1 + "." + di.Name);

}

Console.Write("enter your choice:");

choice = Console.ReadLine();

Console.Clear();

Console.WriteLine("**** Select Log-Index ****");

Console.WriteLine("index\t\tDate");

string[] logDate = Directory.GetDirectories(logSource[int.Parse(choice) - 1]);

Console.ForegroundColor = ConsoleColor.Red;

for (int i = 0; i < logDate.Length; i++)

{

DirectoryInfo di = new DirectoryInfo(logDate[i]);

string[] logIndex = Directory.GetFiles(logDate[i]);

for (int j = 0; j < logIndex.Length; j++)

{

FileInfo fi = new FileInfo(logIndex[j]);

Console.WriteLine(fi.Name.Remove(fi.Name.IndexOf(".log")) + "\t" + di.Name);

}

}

Console.Write("enter Index-Number:");

string fileName = Console.ReadLine();

for (int i = 0; i < logDate.Length; i++)

{

if (File.Exists(logDate[i] + "\\" + fileName + ".log"))

{

string FileData = File.ReadAllText(logDate[i] + "\\" + fileName + ".log");

string getedData = "";

int count = 0;

for (int r = 0; r < FileData.Length; r++)

{

if (FileData[r].ToString() == " ")

{

count++;

}

}

string[] w_list = new string[count];

int w_index = 0;

for (int r = 0; r < FileData.Length; r++)

{

if (FileData[r].ToString() == " ")

{

w_index++;

}

else

{

w_list[w_index] += FileData[r].ToString(); ;

}

}

for (int ii = 0; ii < w_list.Length; ii++)

{

int w = 0;

if (w_list[ii][w_list[ii].Length - 1].ToString() == "A")

{

w = 10;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "B")

{

w = 11;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "C")

{

w = 12;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "D")

{

w = 13;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "E")

{

w = 14;

}

else if (w_list[ii][w_list[ii].Length - 1].ToString() == "F")

{

w = 15;

}

else

{

w =
int.Parse(w_list[ii][w_list[ii].Length - 1].ToString());

}

string temp = "";

for (int iii = 0; iii < w_list[ii].Length - 1; iii++)

{

temp += w_list[ii][iii].ToString();

}

getedData +=
Convert.ToChar((int.Parse(temp) * 16) + w).ToString();

}

Console.ResetColor();

Console.ForegroundColor = ConsoleColor.DarkGreen;

Console.WriteLine(getedData);

break;

}

}

 

}

else if (choice == "2")

{

Console.WriteLine("1.Change Password");

ConsoleKeyInfo ki = new ConsoleKeyInfo();

ki= Console.ReadKey();

if (ki.KeyChar.ToString() == "1")

{

Console.Clear();

Console.Write("enter your Current Password:");

string currentPassword = "";

while (true)

{

ConsoleKeyInfo kii = new ConsoleKeyInfo();

kii = Console.ReadKey();

if (kii.Key == ConsoleKey.Enter)

{

break;

}

currentPassword += kii.KeyChar.ToString();

Console.Write(Convert.ToChar(8));

Console.Write("*");

}

Console.WriteLine();

Console.Write("enter your new Password:");

string newPassword = "";

while (true)

{

ConsoleKeyInfo kii = new ConsoleKeyInfo();

kii = Console.ReadKey();

if (kii.Key == ConsoleKey.Enter)

{

break;

}

newPassword += kii.KeyChar.ToString();

Console.Write(Convert.ToChar(8));

Console.Write("*");

}

Console.WriteLine();

Console.Write("enter your new Password:");

string confPassword = "";

while (true)

{

ConsoleKeyInfo kii = new ConsoleKeyInfo();

kii = Console.ReadKey();

if (kii.Key == ConsoleKey.Enter)

{

break;

}

confPassword += kii.KeyChar.ToString();

Console.Write(Convert.ToChar(8));

Console.Write("*");

}

if (newPassword == confPassword)

{

if (currentPassword == p)

{

try

{

OleDbCommand commUp = new OleDbCommand("update t1 set password='" + newPassword + "' where username='" + userName + "'", con);

con.Open();

commUp.ExecuteNonQuery();

con.Close();

Console.WriteLine("Password changed");

}

catch (Exception ei)

{

Console.WriteLine(ei.Message);

}

}

else

{

Console.WriteLine("Invalid Password");

}

}

else

{

Console.WriteLine("password misMatch");

}

}

}

else if (choice == "3")

{

Console.ResetColor();

Console.ForegroundColor = ConsoleColor.Red;

Console.WriteLine("Closing application...");

Thread.Sleep(1000);

Thread.CurrentThread.Abort();

}

 

Console.ReadLine();

Console.Clear();

Console.ResetColor();

goto top;

}

}

}

}

project screenshot

output screen




Database screen: db1.mdb



by:Pankaj Sharma