Esempio n. 1
0
 /// <summary>
 /// 更改密码
 /// </summary>
 public static void ChangePassword(string password)
 {
     if (string.IsNullOrEmpty(password))
     {
         password = "******";
     }
     else
     {
         password = NumCalculation.GetStringMd5(password);
     }
     _litedb.Shrink(password);
 }
Esempio n. 2
0
 /// <summary>
 /// 判断指定的数据库密码是否正确
 /// </summary>
 public static bool IsPassword(string password)
 {
     if (string.IsNullOrEmpty(password))
     {
         password = "******";
     }
     else
     {
         password = NumCalculation.GetStringMd5(password);
     }
     try
     {
         LiteEngine liteEngine = new LiteEngine(_dataFile, password);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
        /// <summary>
        /// 用指定的密码打开LiteDb数据库文件,如果不成功将返回Flase
        /// </summary>
        public static bool Open(string password)
        {
            try
            {
                _dataFile = $"{UserSettings.AppdDataDir}\\RemoteItems.db";
                if (!File.Exists(_dataFile))//新建数据库文件
                {
                    File.WriteAllBytes(_dataFile, Resources.RemoteItems);
                }
                if (string.IsNullOrEmpty(password))
                {
                    password = "******";
                }
                else
                {
                    password = NumCalculation.GetStringMd5(password);
                }
                //验证密码是否正确
                try { LiteEngine liteEngine = new LiteEngine(_dataFile, password); }
                catch { return(false); };

                _litedb = new LiteDatabase($"Filename={_dataFile};Password={password}");
                _litedb.Mapper.EmptyStringToNull = false;
                _litedb.Mapper.TrimWhitespace    = false;

                _tableDirectory      = _litedb.GetCollection <DbItemDirectory>("Directory");
                _tableRemoteLink     = _litedb.GetCollection <DbItemRemoteLink>("RemoteLink");
                _tableSetting_rdp    = _litedb.GetCollection <DbItemSetting_rdp>("Setting_rdp");
                _tableSetting_ssh    = _litedb.GetCollection <DbItemSetting_ssh>("Setting_ssh");
                _tableSetting_telnet = _litedb.GetCollection <DbItemSetting_telnet>("Setting_telnet");
                _tableSshHostKeys    = _litedb.GetCollection <DbSshHostKeys>("SshHostKeys");
                _tablePuttyColor     = _litedb.GetCollection <DbPuttyColor>("PuttyColor");
                return(true);
            }
            catch (Exception e)
            {
                throw new Exception($"打开数据库文件失败。\n原因:{e.Message}");
            }
        }