Skip to main content

[CSHAR] Tạo mật khẩu cho file Microsoft Access và Tool giải mã password

Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách tạo mật khẩu bảo mật cho file database Microsoft Access (*.mdb) trong lập trình C# winform.

[C#] Lập trình cài đặt mật khẩu cho file Microsoft Access và tool giải mã password MDB

Trong lập trình kết nối cơ sở dữ liệu OleDB (Access) với C#, chúng ta muốn bảo mật database của mình lại.

Để cài đặt mật khẩu cho file Database Access, các bạn sử dụng câu lệnh sau:
ALTER DATABASE PASSWORD 'matkhaucu', 'matkhaumoi'
Bài viết chỉ ứng dụng cho File Micsoft Acess có định dạng là *.MDB thôi nhé.

Source code Tạo mật khẩu Database Access C#:

using System;
using System.Data.OleDb;
using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Linq;
namespace setaccesspass
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "MS-Access (*.mdb)|*.mdb";
            if (openFileDialog1.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            if (openFileDialog1.FileName.Equals(String.Empty))
            {
                MessageBox.Show("Please enter a file name.", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            txtfilename.Text = openFileDialog1.FileName;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            setpassword(txtfilename.Text, txtoldpassword.Text, txtnewpassword.Text);
        }

        private void setpassword(string FilePath, string OldPassword, string NewPassword)
        {
            try
            {
                if (File.Exists(FilePath))
                {
                    string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + FilePath + ";Jet OLEDB:Database Password=" + OldPassword + ";Mode=12";
                    string OledbConnectionString = conString;
                    using (OleDbConnection con = new OleDbConnection(OledbConnectionString))
                    {
                        string sql = string.Empty;
                        sql = string.Format("ALTER DATABASE PASSWORD [{0}] [{1}]", NewPassword, OldPassword);
                        OleDbCommand cmd = new OleDbCommand(sql, con);

                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                        MessageBox.Show("Password set successfully.");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

    }
}

Còn muốn lấy mật khẩu của file Acess MDB, các bạn có thể chạy file accesspv.exe, mình có để trong thư mục source download.

Chúc mọi người thành công.

Nếu mọi người chưa rỏ về bộ source trên thì có thể tại full source bên dưới để tìm hiểu rỏ nhé.
Comment Policy: Silahkan tuliskan komentar Anda yang sesuai dengan topik postingan halaman ini. Komentar yang berisi tautan tidak akan ditampilkan sebelum disetujui.
Buka Komentar
Tutup Komentar