// 對未加密的SQLite資料庫執行密碼設置操作
// <param name="lszNewPassword">密碼

 public bool SetPassword(string lszPassword) if (IsNoEncrypted()) SQLiteConnectionStringBuilder lbuilder = new SQLiteConnectionStringBuilder();

lbuilder.DataSource = this.pszDBPath;

 

try using (SQLiteConnection lconnection = new System.Data.SQLite.SQLiteConnection()) lconnection.ConnectionString = lbuilder.ConnectionString;
lconnection.Open();
lconnection.ChangePassword(lszPassword);

 

return true; }
catch return false; }
else return false; }

 

//##############################################################################

 

// 對加密的SQLite資料庫執行密碼更改操作
// <param name="lszOldPassword">舊密碼
// <param name="lszNewPassword">新密碼

 

public bool ModifyPassword(string lszOldPassword, string lszNewPassword) SQLiteConnectionStringBuilder lbuilder = new SQLiteConnectionStringBuilder();
lbuilder.DataSource = this.pszDBPath;
if (lszOldPassword != null && lszOldPassword != "") lbuilder.Password = lszOldPassword;
}

 

try using (SQLiteConnection lconnection = new System.Data.SQLite.SQLiteConnection()) try lconnection.ConnectionString = lbuilder.ConnectionString;
lconnection.Open();
lconnection.ChangePassword(lszNewPassword);

 

return true; catch return false; } catch return false; }

 

//##############################################################################

 

// 判斷SQLite資料庫是否有設置密碼

 

public bool IsNoEncrypted() SQLiteConnectionStringBuilder lbuilder = new SQLiteConnectionStringBuilder();
lbuilder.DataSource = this.pszDBPath;

 

using (SQLiteConnection lconnection = new System.Data.SQLite.SQLiteConnection()) lconnection.ConnectionString = lbuilder.ConnectionString;
try lconnection.Open();
return true; catch return false; finally lconnection.Close(); }
}
創作者介紹
創作者 shadow 的頭像
shadow

資訊園

shadow 發表在 痞客邦 留言(0) 人氣()