Source code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.AccessControl;
using System.IO;
using Finisar.SQLite; // SQlite Library
namespace folderLockerWithPass
{
public partial class mainform : Form
{
public mainform()
{
InitializeComponent();
}
private SQLiteConnection sql_con;
private SQLiteCommand sql_cmd;
private void SetConnection()
{
sql_con = new SQLiteConnection("Data Source=test.db;Version=3;New=False;Compress=false;");
}
private void SelectQuery()
{
string textSQLQuery = "Select NewPassword From UserInfo where NewPassword='" + PasswordConfirm.Text + "' ";
ExecuteQuery(textSQLQuery);
}
private void UpdateQuery()
{
string UpateQuery="UPDATE UserInfo SET NewPassword='"+newPasstb.Text+"' where NewPassword='"+currentPasstb.Text+"'";
ExecuteQuery(UpateQuery);
}
private void ExecuteQuery(string txtQuery)
{
SetConnection();
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
sql_cmd.CommandText = txtQuery;
sql_cmd.ExecuteNonQuery();
sql_con.Close();
}
private bool Down_Mouse;// variables
private Point MouseFirstPoint; // to move form with out borders
private void lockFolder()
{
// Locking the folder as follow
try
{
string folderPath = fpath.Text;
string adminUserName = Environment.UserName;
DirectorySecurity ds = Directory.GetAccessControl(folderPath);
FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);
ds.AddAccessRule(fsa);
Directory.SetAccessControl(folderPath, ds);
}
catch (Exception ex)
{
}
}
private void unlockFoldercode()
{
//Unlock the folder as follow
try
{
string folderPath = fpath.Text;
string adminUserName = Environment.UserName;
DirectorySecurity ds = Directory.GetAccessControl(folderPath);
FileSystemAccessRule fsa = new FileSystemAccessRule(adminUserName, FileSystemRights.FullControl, AccessControlType.Deny);
ds.RemoveAccessRule(fsa);
Directory.SetAccessControl(folderPath, ds);
}
catch (Exception ex)
{
}
}
private void lockbtn_Click(object sender, EventArgs e)
{
if (fpath.Text != "" && lockrbtn.Checked==true)
{
ChangPassGb.Hide();
mainstatus.Text = "Confirm Password ";
lockPanel.Show();
label1.Text="Confirm Your Password To Lock Folder ";
}
if (fpath.Text != "" && unlockrbtn.Checked == true)
{
mainstatus.Text = "Confirm Password ";
lockPanel.Show();
label1.Text = "Confirm Your Password To Unlock Folder";
}
else mainstatus.Text = "Status :Select Folder First !";
}
private void mainform_Load(object sender, EventArgs e)
{
this.lockrbtn.Checked = true;
lockPanel.Hide();
ChangPassGb.Hide();
}
private void confirmpassbtn_Click(object sender, EventArgs e)
{
SelectQuery();
sql_con.Open();
SQLiteDataReader dr = sql_cmd.ExecuteReader();
int count = 0;
string Password = "";
while (dr.Read())
{
count++;
Password = dr[0].ToString();
}
if (count== 1 && lockrbtn.Checked==true)
{
lockFolder();
mainstatus.Text = "Status : Folder locked Successfully!";
lockPanel.Hide();
}
if (count == 1 && unlockrbtn.Checked == true)
{
unlockFoldercode();
mainstatus.Text = "Status : Folder Unlocked Successfully";
lockPanel.Hide();
}
else
{
PasswordConfirm.BackColor = Color.Tomato;
label1.Text = "Wrong Password Please Try Again !";
}
}
private void aboutbtn_Click(object sender, EventArgs e)
{
lockPanel.Hide();
}
private void linkLabel1_Click(object sender, EventArgs e)
{
lockPanel.Hide();
}
private void mainform_MouseDown(object sender, MouseEventArgs e)
{
Down_Mouse = true;
Cursor.Hide();
}
private void mainform_MouseUp(object sender, MouseEventArgs e)
{
Down_Mouse = false;
Cursor.Show();
}
private void mainform_MouseMove(object sender, MouseEventArgs e)
{
if (Down_Mouse) // For to Detect current position of mouse on form and make it moveable with out default Form Control
{
int x = MouseFirstPoint.X - e.Location.X;
int y = MouseFirstPoint.Y - e.Location.Y;
int NewPointx = this.Location.X - x;
int NewPointy = this.Location.Y - y;
this.Location = new Point(NewPointx, NewPointy);
}
}
private void browse_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
fpath.Text = folderBrowserDialog1.SelectedPath;
mainstatus.Text = "Status :Folder Selected!";
}
}
private void PasswordConfirm_Click(object sender, EventArgs e)
{
if (lockrbtn.Checked == true)
label1.Text = "Confirm Your Password To Lock Folder";
else if (unlockrbtn.Checked == true)
label1.Text = "Confirm Your Password To Unlock Folder ";
PasswordConfirm.Text = "";
PasswordConfirm.BackColor = Color.White;
}
private void linkLabel3_Click(object sender, EventArgs e)
{
lockPanel.Hide();
}
private void linkLabel3_Click_1(object sender, EventArgs e)
{
ChangPassGb.Show();
}
private void changpassBtn_Click(object sender, EventArgs e)
{
if (newPasstb.Text == conNewPasstb.Text)
{
string NewPassword = newPasstb.Text;
SetConnection();
sql_con.Open();
UpdateQuery();
label4.Text = "Password Successfully Changed !";
}
else
{
label4.Text = "Passwords Does Not Matched ";
newPasstb.BackColor = Color.Tomato;
conNewPasstb.BackColor = Color.Tomato;
}
}
private void linkLabel1_Click_2(object sender, EventArgs e)
{
ChangPassGb.Hide();
}
private void label9_Click(object sender, EventArgs e)
{
ChangPassGb.Hide();
}
private void label3_Click(object sender, EventArgs e)
{
lockPanel.Hide();
}
private void linkL_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("www.faccebook.com/ziabse");
}
}
}
No comments:
Post a Comment