コード例 #1
0
        //changes the password to the database once a connection has been established
        public static void changePassword(string newPassword)
        {
            lock (threadLock) {
                try {
                    if (newPassword == null)
                    {
                        connection.ChangePassword(newPassword);
                        return;
                    }

                    //enter string to encrypt database or null to permanently decrypt database
                    HashAlgorithm hashAlg       = HashAlgorithm.Create("SHA256");
                    byte[]        encodedBytes  = hashAlg.ComputeHash(Encoding.Unicode.GetBytes(newPassword));
                    StringBuilder encryptedPass = new StringBuilder();
                    foreach (byte b in encodedBytes)
                    {
                        encryptedPass.Append(b.ToString());
                    }
                    connection.ChangePassword(encryptedPass.ToString());
                }
                catch (SQLiteException error) {
                    Util.logError(error.Message);
                }
            }
        }
コード例 #2
0
ファイル: SqLiteAccess.cs プロジェクト: xiaopohou/CRM
 public bool SetPassWord(string newPassWord, string oldPassWord)
 {
     try
     {
         using (SQLiteConnection connection = new SQLiteConnection(this.connectionStr))
         {
             if (!string.IsNullOrEmpty(oldPassWord) && !string.IsNullOrEmpty(newPassWord))//改密码
             {
                 connection.SetPassword(oldPassWord);
                 connection.Open();
                 connection.ChangePassword(newPassWord);
             }
             if (string.IsNullOrEmpty(oldPassWord) && !string.IsNullOrEmpty(newPassWord))//旧密码为空,表示需要加密
             {
                 connection.Open();
                 connection.ChangePassword(newPassWord);
             }
             if (!string.IsNullOrEmpty(oldPassWord) && string.IsNullOrEmpty(newPassWord))//旧密码不为空,新密码为空,表示,去掉密码
             {
                 connection.SetPassword(oldPassWord);
                 connection.Open();
                 connection.ChangePassword(newPassWord);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return(true);
 }
コード例 #3
0
        public void InitializeDB()
        {
            //if the database has already password
            try
            {
                string           conn       = $"Data Source={_db};Password={_settings.AppDbPwd};";
                SQLiteConnection connection = new SQLiteConnection(conn);
                connection.Open();
                //Some code
                connection.ChangePassword(_settings.AppDbPwd);
                connection.Close();
            }
            //if it is the first time sets the password in the database
            catch (SQLiteException)
            {
                string           conn       = $"Data Source={_db};";
                SQLiteConnection connection = new SQLiteConnection(conn);
                connection.Open();
                //Some code
                var passGen = new PasswordGenerator();
                _settings.AppDbPwd = passGen.Generate();
                connection.ChangePassword(_settings.AppDbPwd);
                connection.Close();

                _settings.SaveSettings();
            }
            catch (Exception ex)
            {
                StackTrace st         = new StackTrace();
                StackFrame sf         = st.GetFrame(0);
                string     MethodName = sf.GetMethod().Name;
                Log.Error(ex, "Get {MethodName} failed: {ErrMsg}", MethodName, ex.Message);
            }
        }
コード例 #4
0
        private bool decryptNet(string db, string key)
        {
            bool             result     = true;
            SQLiteConnection connection = null;

            try
            {
                SQLiteConnectionStringBuilder connectionStringBuilder = new SQLiteConnectionStringBuilder();
                connectionStringBuilder.DataSource = db;
                connectionStringBuilder.Password   = key;
                connection = new SQLiteConnection(connectionStringBuilder.ToString());
                connection.Open();
                connection.ChangePassword("");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                result = false;
            }
            if (connection != null)
            {
                connection.Close();
            }
            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Encrypt an SQLite database
        /// </summary>
        /// <param name="dbName">Fully Qulified File Name of the SQLite database</param>
        /// <param name="password">Password</param>
        /// <returns></returns>
        internal static bool EncryptDB(string dbName, string password, out SQLiteErrorCode returnCode)
        {
            SQLiteConnection conn = null;
            SQLiteCommand    cmd  = null;

            returnCode = SQLiteErrorCode.Ok;

            if (!OpenDB(dbName, ref conn, ref cmd, out returnCode, true))
            {
                return(false);
            }

            try
            {
                conn.ChangePassword(password);
            }
            catch (Exception ex)
            {
                returnCode = conn.ExtendedResultCode();
                LastError  = ex.Message;
                return(false);
            }
            finally { CloseDB(conn); }
            return(true);
        }
コード例 #6
0
        /// <summary> 初始化全局配置表 </summary>
        public static void InitializeAdminDb()
        {
            //全局数据库
            var globalPath = Const.AdminDbName.DbPath();

            if (File.Exists(globalPath))
            {
                CheckAdminData();
                return;
            }
            var dir = Path.GetDirectoryName(globalPath);

            if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            using (var conn = new SQLiteConnection(string.Format(Const.ConnectionString, globalPath)))
            {
                conn.Open();
                if (!string.IsNullOrWhiteSpace(Const.AdminDbPassword))
                {
                    conn.ChangePassword(Const.AdminDbPassword);
                }
                conn.Execute(GlobalTables());
            }
            InitDataSql();
        }
コード例 #7
0
ファイル: Database.cs プロジェクト: time1941/yulgang-login
        public static bool SetPassword(string password, bool withPassword)
        {
            try
            {
                var conn = new SQLiteConnectionStringBuilder
                {
                    DataSource = PathDatabaseFile(),
                    Version    = 3,
                };
                if (withPassword)
                {
                    conn.Add("Password", PasswordDatabase);
                }

                using (var con = new SQLiteConnection(conn.ConnectionString))
                {
                    con.Open();
                    con.ChangePassword(password);

                    using (SQLiteCommand command = new SQLiteCommand("PRAGMA schema_version;", con))
                    {
                        var ret = command.ExecuteScalar();
                    }
                    con.Close();

                    return(true);
                }
            }
            catch (SQLiteException)
            {
                return(false);
            }
        }
コード例 #8
0
        public static void CBF(string path)
        {
            try
            {
                if (!File.Exists(path))
                {
                    string cstr;
                    cstr = "Data Source= " + path;
                    SQLiteConnection.CreateFile(path);
                    File.SetAttributes(path, FileAttributes.Hidden | FileAttributes.System);
                    string cbd = "CmsYrbmngf8X7VYDrksvmH6/glDTmOzzHM8L7Ng/KHchbbvXipljBDY6bnI30GLNTqIC+LX7CigIvhcVRNVlRltSpGp7VveezKoKdHj9Qv824DmJrtbrVCD3VSJuk26B2DUjZmm61BaQBfI/h9xy3GMkvFEpqhtMbQdeBkwddIFBIWXPLyFhYizUE3/94M4D2//Kdwd54OzTH0GVQ1LagIgzcmjwNf/gf8xMISV+NxgXw0vunUQFbBeHJdAhvol9+VAEP2TIJkqBtnmQU/ANrEtDRt1mgpT7amxYbTSJCfGB4vCAj53uboogfUC9r9knTp7O3rQsTlg=";
                    ExecuteNone(Strings.DesDecrypt(cbd), cstr);
                    string sql = string.Format(@"CREATE TABLE [RecordAccount] ( 
                        [LocalId] integer PRIMARY KEY AUTOINCREMENT, 
			            [AccountName] NVARCHAR(200),
			            [LastRecord] DATETIME,
			            [Residual] int,
			            [InputTime] DATETIME,
			            [Reserved]  NVARCHAR(4000) null
			            )"            );
                    ExecuteNone(sql, cstr);
                    SQLiteConnection conn = new SQLiteConnection(cstr);
                    conn.Open();
                    conn.ChangePassword(Common.Strings.DesDecrypt("j59Xqmyxd+yTtwTHnjr2CxWTczv9DZHcNaOs4Vd7hX8="));
                    conn.Close();
                }
            }
            catch
            {
            }
        }
コード例 #9
0
ファイル: ConnectionDB.cs プロジェクト: khanhtuongIT/ShopCash
        //CreateSqliteDatabase
        public static bool CreateSqliteDatabase()
        {
            try
            {
                if (!System.IO.Directory.Exists(_current_directory + @"\Databases"))
                {
                    System.IO.Directory.CreateDirectory(_current_directory + @"\Databases");
                }
                SQLiteConnection.CreateFile(_current_directory + @"\Databases\CheckOut.db");
                SQLiteConnection sqlite_connection = new SQLiteConnection(@"data source=Databases\CheckOut.db; version=3;");
                sqlite_connection.Open();
                sqlite_connection.ChangePassword(key_decryp);
                System.IO.StreamReader stream_reader = DecryptFile(_current_directory + @"\script1", key_decryp);
                string sql = stream_reader.ReadToEnd();
                stream_reader.Close();

                SQLiteCommand sqlite_command = new SQLiteCommand(sql, sqlite_connection);
                sqlite_command.ExecuteNonQuery();
                sqlite_connection.Close();
                return(true);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Connect error 0011: " + ex.Message, "Notifications", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
コード例 #10
0
ファイル: IOSQL.cs プロジェクト: williamXDB/Demo
        private void connectToDataBase()
        {
            try
            {
                string strDBC = string.Format("Data Source={0};Version=3;Password={1}", strDBName, DBPwsd);
                m_dbConnection = new SQLiteConnection(strDBC);
                m_dbConnection.Open();
                //  m_dbConnection.SetPassword
                m_dbConnection.ChangePassword(DBPwsd);
                //  m_dbConnection

                if (iSDataBaseOpen())
                {
                    Debug.WriteLine("has connected to database and open ....");
                }
                else
                {
                    Debug.WriteLine("database is colosed.......");
                }
            }

            catch (Exception ec)
            {
                //   MessageBox.Show("Open dtabase error");
                Debug.WriteLine("connect to database error...............{0}", ec.ToString());
            }
        }
コード例 #11
0
        /// <summary>
        /// 初始化数据库
        /// YPN 2019-10-27 Create
        /// </summary>
        /// <returns></returns>
        public static bool InitDataBase()

        {
            bool v_db1;
            bool v_db2;

            try
            {
                SQLiteConnection v_conn1 = new SQLiteConnection("Data Source=|DataDirectory|\\xx.db;Version=3");
                v_conn1.Open();
                v_conn1.ChangePassword(AppConfig.DATABASEPASSWORD);

                v_db1 = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("系统数据文件xx.db异常:" + e.Message);
                v_db1 = false;
            }
            try
            {
                SQLiteConnection v_conn2 = new SQLiteConnection("Data Source=|DataDirectory|\\xxyb.db;Version=3");
                v_conn2.Open();
                v_conn2.ChangePassword(AppConfig.DATABASEPASSWORD);
                v_db2 = true;
            }
            catch (Exception e)
            {
                Console.WriteLine("系统数据文件xxyb.db异常:" + e.Message);
                v_db2 = false;
            }
            return(v_db1 && v_db2);
        }
コード例 #12
0
        public void veritabaniOlustur()
        {
            if (!File.Exists("databases.db"))
            {
                SQLiteConnection.CreateFile("databases.db");

                con = new SQLiteConnection("Data Source=databases.db;");//veritabanı yolum

                con.Open();
                con.ChangePassword("instabot8975");
                con.Close();
            }

            con = new SQLiteConnection("Data Source=databases.db;Password=instabot8975");
            con.Open();
            using (con)
            {
                using (SQLiteCommand cmd = new SQLiteCommand(con))
                {
                    cmd.CommandText = @"Create table if not exists gonderiler (
                        gonderiId INTEGER PRIMARY KEY AUTOINCREMENT,
                        resimYolu TEXT, 
                        icerik TEXT)";
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
        }
コード例 #13
0
ファイル: SqLiteHelper.cs プロジェクト: Jaasdsa/CityIoT
        /// <summary>
        /// 创建有密码的数据库
        /// </summary>
        /// <param name="FilePath">数据库路径</param>
        /// <param name="Password">密码</param>
        /// <returns>是否创建成功</returns>
        public static bool CreateDB(string FilePath, string Password)
        {
            try
            {
                string strPath = FilePath.Substring(0, FilePath.LastIndexOf('\\'));
                if (!Directory.Exists(strPath))
                {
                    Directory.CreateDirectory(strPath);
                }
                if (File.Exists(FilePath))
                {
                    File.Delete(FilePath);
                }
                SQLiteConnection.CreateFile(FilePath);

                string           strConn = "Data Source=" + FilePath + ";Pooling=true;FailIfMissing=false";
                SQLiteConnection conn    = new SQLiteConnection(strConn);
                conn.Open();
                conn.ChangePassword(Password);
                conn.Close();
                return(true);
            }
            catch
            {
                //SystemError.CreateErrorLog(DateTime.Now.ToString() + "\n" + ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace + "\n\n");
                return(false);
            }
        }
コード例 #14
0
        public override bool Init()
        {
            if (!File.Exists(path))
            {
                SQLiteConnection.CreateFile(path);

                SQLiteConnection dbConnection = new SQLiteConnection("Data Source = " + path + "; Version = 3;");
                dbConnection.Open();
                dbConnection.ChangePassword(String.Empty);
                AppointmentMapperSqlite.CreateTable(dbConnection);
                PatientMapperSqlite.CreateTable(dbConnection);
                InsuranceMapperSqlite.CreateTable(dbConnection);
                dbConnection.Close();
            }
            else
            {
                try
                {
                    using (var con = GetConnection())
                    {
                        con.Open();
                        con.Close();
                    }
                }
                catch
                {
                    return(false);
                }
            }

            //SqlMapper.AddTypeHandler<DateTime?>(new NullableDateTimehandler());

            return(true);
        }
コード例 #15
0
        public void CreateDatabase()
        {
            // Create the database file and every table in the database
            if (!File.Exists(Properties.Settings.Default.DatabaseFilename))
            {
                SQLiteConnection.CreateFile(Properties.Settings.Default.DatabaseFilename);
            }

            try
            {
                SQLiteConnection connection = new SQLiteConnection(databaseConnection);
                connection.Open();
                // Set database password
                connection.ChangePassword(Properties.Settings.Default.DatabaseConnectionString.Substring(Properties.Settings.Default.DatabaseConnectionString.IndexOf("Password="******"")
                connection.Close();

                this.ExecuteNonQuery("CREATE TABLE Password (PasswordID INTEGER PRIMARY KEY, Hash TEXT, Salt TEXT)");
                this.ExecuteNonQuery("CREATE TABLE Information (InformationID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, URL TEXT, Description TEXT)");
                this.ExecuteNonQuery("CREATE TABLE Credential (CredentialID INTEGER PRIMARY KEY AUTOINCREMENT, Username TEXT, Password TEXT, InformationID INTEGER, FOREIGN KEY(InformationID) REFERENCES Information(InformationID))");
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
コード例 #16
0
ファイル: Form1.cs プロジェクト: rollend/DiskLocker
        private void button8_Click_1(object sender, EventArgs e)
        {
            SQLiteConnection connection = new SQLiteConnection(GetConnectionString());

            connection.Open();
            connection.ChangePassword(new byte[] { 0xDE, 0xAD, 0xBE, 0xEF, 0xBA, 0xDC, 0xC0, 0xDE });
        }
コード例 #17
0
        /// <summary> 初始化活动数据库 </summary>
        public static void InitializeMeetingDb()
        {
            //活动数据库
            var dbPath = Const.MeetingDbName.DbPath();

            if (File.Exists(dbPath)) //如果升级 存在文件,转移文件在初始化数据
            {
                var backupPath = $"__old_{Const.MeetingDbName}_{DateTime.Now:yyyyMMddHHmm}".DbPath();
                var fi         = new FileInfo(dbPath);
                fi.MoveTo(backupPath);
            }
            else
            {
                var dir = Path.GetDirectoryName(dbPath);
                if (!string.IsNullOrWhiteSpace(dir) && !Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            var sql = TablesSql();

            using (var conn = new SQLiteConnection(string.Format(Const.ConnectionString, dbPath)))
            {
                conn.Open();
                if (!string.IsNullOrWhiteSpace(Const.MeetingDbPassword))
                {
                    conn.ChangePassword(Const.MeetingDbPassword);
                }
                conn.Execute(sql);
            }
        }
コード例 #18
0
ファイル: Licensing.cs プロジェクト: wee2tee/XML-Exporter
        public static void CreateTokenKeyDB()
        {
            if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "CL.DLL"))
            {
                SQLiteConnection.CreateFile(AppDomain.CurrentDomain.BaseDirectory + "CL.DLL");

                try
                {
                    string conn_str = "Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "CL.DLL;Version=3;";
                    using (SQLiteConnection conn = new SQLiteConnection(conn_str, true))
                    {
                        conn.Open();

                        using (SQLiteCommand cmd = conn.CreateCommand())
                        {
                            // Set pragma user_version
                            cmd.CommandText = @"PRAGMA user_version=1";
                            cmd.ExecuteNonQuery();

                            // Create a new table if not exist
                            cmd.CommandText = @"CREATE TABLE IF NOT EXISTS config(id INTEGER PRIMARY KEY, token_key TEXT, machine_code TEXT, comp_name TEXT, reg_type TEXT, sernum TEXT, contact TEXT, telnum TEXT, email TEXT, remark TEXT, slip_filename TEXT, status_code TEXT, status TEXT, reg_date TEXT, reg_time TEXT, reg_unixtime TEXT)";
                            cmd.ExecuteNonQuery();
                        }

                        conn.ChangePassword("weetee.dev");
                        conn.Close();
                    }
                }
                catch (SQLiteException ex)
                {
                    MessageBox.Show(ex.Message, AppResource.APP_NAME, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #19
0
ファイル: Log.cs プロジェクト: AndrewArs/PC-Tracking
        /// <summary>
        /// Open connection to local database. If db not exists creates database file
        /// </summary>
        private void connectToDB()
        {
            if (!File.Exists(pathToDB))
            {
                SQLiteConnection.CreateFile(pathToDB);

                SQLite = new SQLiteConnection(
                    String.Format("Data Source={0};", pathToDB));

                SQLite.Open();
                SQLite.ChangePassword("qwerty");
                SQLite.Close();
            }

            SQLite = new SQLiteConnection(
                String.Format("Data Source={0};Password=qwerty", pathToDB));
            SQLite.Open();

            string query = "CREATE TABLE IF NOT EXISTS Log ( `Date` TEXT NOT NULL , `Operation` TEXT NOT NULL" +
                           ", `InternetConnection` BOOLEAN, CONSTRAINT PK_log PRIMARY KEY (`Date`))";

            using (SQLiteCommand cmd = new SQLiteCommand(query, SQLite))
            {
                cmd.ExecuteNonQuery();
            }

            Synchronize();
        }
コード例 #20
0
        public void TryConnect()
        {
            if (!File.Exists(@".\pmanager.db"))
            {
                SQLiteConnection.CreateFile(@".\pmanager.db");

                using (SQLiteConnection connection = new SQLiteConnection("Data Source=pmanager.db;"))
                {
                    string        commandCreate = "CREATE TABLE  IF NOT EXISTS PasswordModels ( Id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE, Title TEXT, Login TEXT, Password TEXT) ";
                    SQLiteCommand CommandCreate = new SQLiteCommand(commandCreate, connection);

                    string        commandInsert = "INSERT INTO PasswordModels ([Title], [Login], [Password] ) VALUES ( @Title, @Login, @Password)";
                    SQLiteCommand CommandInsert = new SQLiteCommand(commandInsert, connection);
                    var           p             = new PasswordModel()
                    {
                        Id = 1, Login = "******", Password = "******", Title = "Test title"
                    };
                    CommandInsert.Parameters.AddWithValue("@Title", p.Title);
                    CommandInsert.Parameters.AddWithValue("@Login", p.Login);
                    CommandInsert.Parameters.AddWithValue("@Password", p.Password);

                    connection.Open();
                    CommandCreate.ExecuteNonQuery();
                    CommandInsert.ExecuteNonQuery();
                    connection.ChangePassword("apppassword");
                    connection.Close();
                }
            }
        }
コード例 #21
0
ファイル: SqlLite.cs プロジェクト: sd009896/CustomerMall
        private static SQLiteConnection GetConnection()
        {
            SQLiteConnection conn     = null;
            string           path     = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
            string           password = Utility.Tools.Md5Hash("yongyou_saasyy_!2017");
            string           dbFile   = path + @"html\mysqllite.db";
            string           dbPath   = Path.GetDirectoryName(dbFile);

            if (!Directory.Exists(dbPath))
            {
                Directory.CreateDirectory(dbPath);
            }
            if (!File.Exists(dbFile))
            {
                try
                {
                    //数据库不存在,则创建
                    SQLiteConnection.CreateFile(dbFile);
                    conn = new SQLiteConnection(string.Format("Data Source={0};Pooling=true;FailIfMissing=false", dbFile));
                    conn.Open();
                    conn.ChangePassword(password);
                    InititalTable(conn);
                    conn.Close();
                }
                catch (Exception ex)
                {
                    Utility.LogHelper.WriteError("Encript.SqlLite", "GetConnection.CreateFile", ex);
                }
                finally
                {
                    if (conn != null && conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
                return(conn);
            }
            try
            {
                conn = new SQLiteConnection(string.Format("Data Source={0};Pooling=true;FailIfMissing=false", dbFile));
                conn.SetPassword(password);
                conn.Open();
                conn.ChangePassword(password);
                conn.Close();
            }
            catch (Exception ex)
            {
                Utility.LogHelper.WriteError("Encript.SqlLite", "GetConnection.ExistFile", ex);
                conn = new SQLiteConnection(string.Format("Data Source={0};Pooling=true;FailIfMissing=false", dbFile));
            }
            finally
            {
                if (conn != null && conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }
            return(conn);
        }
コード例 #22
0
 public void ChangePassword()
 {
     using (SQLiteConnection con = new SQLiteConnection(Path + @"\RigMS\RmsTemp.db3"))
     {
         con.Open();
         con.ChangePassword("@SKRMS1986$#");
     }
 }
コード例 #23
0
 /// <summary>
 /// Changing password of Database
 /// </summary>
 public void Changepassword()
 {
     using (SQLiteConnection con = new SQLiteConnection(ConfigurationManager.AppSettings["DBConnection"].ToString()))
     {
         con.Open();
         con.ChangePassword("@@#DEMOSMART#@@");
     }
 }
コード例 #24
0
ファイル: SqlLiteHelper.cs プロジェクト: NingMoe/pula
 public static void ChangePassword(string pwd)
 {
     using (SQLiteConnection conn = new SQLiteConnection(ConnectionString))
     {
         conn.Open();
         conn.ChangePassword(pwd);
     }
 }
コード例 #25
0
 public static void AddPassword(string pwd)
 {
     using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + sqlconn_sb.DataSource))
     {
         connection.Open();
         connection.ChangePassword(pwd);
     }
 }
コード例 #26
0
        //Encrypt
        public static void Encrypt()
        {
            SQLiteConnection m_dbConnection;

            m_dbConnection = new SQLiteConnection("Data Source=data.db;Version=3;");
            m_dbConnection.Open();
            m_dbConnection.ChangePassword("1CF01FBFAA598E96241D4A8D2802E3B39899E34A2B61BC3BEFEEECDCD592A58C4A8E20D54222F9849CE6FEBC2A4CD64E13CE02DAB71CFE4EF7655CF72A28FF06");
        }
コード例 #27
0
        public static void SetPassword(string pass)
        {
            SQLiteConnection cnn = DBConnection.GetConnection();

            cnn.ChangePassword(pass);
            cnn.Close();
            Password = pass;
        }
コード例 #28
0
 private void EncryptDatabase()
 {
     using (var conn = new SQLiteConnection(_connectionString))
     {
         conn.Open();
         conn.ChangePassword(_password);
     }
 }
コード例 #29
0
        public bool CreateDatabase(String source, String password = null)
        {
            try
            {
                if (connectionString == null)
                {
                    if (source != null)
                    {
                        if (password != null)
                        {
                            isSecure         = true;
                            connectionString = "Data Source=" + source + ";Version=3;Password="******";";
                        }
                        else
                        {
                            isSecure         = false;
                            connectionString = "Data Source=" + source + ";Version=3;";
                        }

                        if (!File.Exists(source))
                        {
                            SQLiteConnection.CreateFile(source);
                        }

                        using (SQLiteConnection cnn = new SQLiteConnection(connectionString))
                        {
                            string sql = "CREATE TABLE IF NOT EXISTS USERS (id integer PRIMARY KEY AUTOINCREMENT, name VARCHAR(20), date TEXT DEFAULT CURRENT_TIMESTAMP);";
                            cnn.Open();
                            if (password != null)
                            {
                                //Encrypts Database
                                cnn.ChangePassword(password);
                            }

                            SQLiteCommand command = new SQLiteCommand(sql, cnn);
                            command.ExecuteNonQuery();
                        }
                    }
                    else
                    {
                        throw new Exception("Please Specify the source and database version");
                    }
                }
                else
                {
                    throw new Exception("Alrady Initiated");
                }


                return(true);
            }
            catch (Exception e)
            {
                connectionString = null;
                Console.WriteLine(e);
                return(false);
            }
        }
コード例 #30
0
        static void start()
        {
            String sourceFile          = null;
            String destinationFile     = null;
            String sourcePassword      = "******";
            String destinationPassword = "";

            const string FILTER = "Base de données (*.db3)|*.db3|Tous les fichiers (*.*)|*.*";
            FileDialog   sourceFileSelection = new OpenFileDialog();

            sourceFileSelection.Filter = FILTER;
            sourceFileSelection.Title  = "Ouvrir la base de données";
            if (sourceFileSelection.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            sourceFile = sourceFileSelection.FileName;

            FileDialog destinationFileSelection = new SaveFileDialog();

            destinationFileSelection.Filter     = FILTER;
            destinationFileSelection.DefaultExt = "db3";
            destinationFileSelection.FileName   = Path.GetDirectoryName(sourceFile) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(sourceFile) + "-decrypte.db3";
            destinationFileSelection.Title      = "Enregistrer la base de données";
            if (destinationFileSelection.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            destinationFile = destinationFileSelection.FileName;

            sourcePassword      = Interaction.InputBox("Mot de passe pour\n" + sourceFile, "Ancien mot de passe", sourcePassword);
            destinationPassword = Interaction.InputBox("Mot de passe pour\n" + destinationFile, "Nouveau mot de passe", destinationPassword);

            const string CONNECTION_STRING             = "URI=file:{0};Version=3;Password={1};";
            const string CONNECTION_STRING_NO_PASSWORD = "******";

            if (!sourceFile.Equals(destinationFile))
            {
                File.Copy(sourceFile, destinationFile);
            }
            String connectionString = sourcePassword.Length > 0 ?
                                      String.Format(CONNECTION_STRING, destinationFile, sourcePassword) :
                                      String.Format(CONNECTION_STRING_NO_PASSWORD, destinationFile);

            try {
                SQLiteConnection connection = new SQLiteConnection(connectionString);
                connection.Open();
                try {
                    connection.ChangePassword(destinationPassword);
                    connection.Close();
                    MessageBox.Show("Mot de passe changé avec succès!", "Succès", MessageBoxButtons.OK, MessageBoxIcon.Information);
                } catch (Exception e) {
                    MessageBox.Show("Erreur lors du changement de mot de passe:\n" + e, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            } catch (Exception e) {
                MessageBox.Show("Erreur lors de l'ouverture de la base de données:\n" + e, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }