Esempio n. 1
0
        public void initItems()
        {
            bool loaded = false;

            if (File.Exists(cfgPath))
            {
                try
                {
                    string rawdata = File.ReadAllText(cfgPath, Encoding.UTF8);
                    cryptor.loadFromXml(rawdata);
                    appSettings = JsonConvert.DeserializeObject <AppSettings>(cryptor.getData());
                    loaded      = true;
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                loaded = false;
            }
            if (!loaded)
            {
                MessageBox.Show("第一次使用请设定主密码");
                string password = FrmInputPassword.CreatePassword(this);
                if (null == password)
                {
                    Application.Exit(); return;
                }
                cryptor.init(password);
                appSettings = new AppSettings();
                for (int i = 0; i < 7; i++)
                {
                    NameItemCollecton nameItemCollection = new NameItemCollecton()
                    {
                        name = "未命名摇号", items = new List <NameItem>()
                    };
                    for (int j = 1; j <= 30; j++)
                    {
                        nameItemCollection.items.Add(new NameItem(j.ToString(), false));
                    }
                    appSettings.nameListCollections.Add(nameItemCollection);
                }
                string json = JsonConvert.SerializeObject(appSettings);

                cryptor.setData(json, password);
                File.WriteAllText(cfgPath, cryptor.exportToXml(), Encoding.UTF8);
            }

            for (int i = 0; i < appSettings.nameListCollections.Count; i++)
            {
                selectionButtons[i].Text = appSettings.nameListCollections[i].name;
            }

            loadItems(appSettings.nameListCollections[selecting].items);
        }
Esempio n. 2
0
 private void btnTestSubpass_Click(object sender, EventArgs e)
 {
     if (testSubPassword(FrmInputPassword.Input(this, "请输入其中一个子密码")) != "")
     {
         MessageBox.Show("子密码认证成功");
     }
     else
     {
         MessageBox.Show("子密码错误或不存在");
     }
 }
Esempio n. 3
0
 private void btnClearSubpass_Click(object sender, EventArgs e)
 {
     if (Form1.cryptor.verifyPassword(FrmInputPassword.Input(this, "请输入主密码确认操作")))
     {
         appSettingObject.subpasswords.Clear();
     }
     else
     {
         MessageBox.Show("主密码错误");
     }
     loadSubPass();
 }
Esempio n. 4
0
        public static string Input(Form owner, String hint)
        {
            bool             ownerToplevel = owner.TopMost;
            String           password      = "";
            FrmInputPassword form          = new FrmInputPassword();

            form.Text = hint;
            if (form.ShowDialog(owner) == DialogResult.OK)
            {
                password = form.textBox1.Text;
            }
            owner.TopMost = ownerToplevel;
            return(password);
        }
Esempio n. 5
0
 private void btnNewSubpass_Click(object sender, EventArgs e)
 {
     MessageBox.Show("添加子密码后,通过子密码可以修改名单。");
     if (Form1.cryptor.verifyPassword(FrmInputPassword.Input(this, "请输入主密码")))
     {
         string subpass = FrmInputPassword.CreatePassword(this);
         if (null == subpass)
         {
             return;
         }
         appSettingObject.subpasswords.Add(FinanceCrypto.CryptoHelper.AesEncrypt("MAINPASS" + FinanceCrypto.CryptoObject.randomMask() + savepassword, subpass));
     }
     else
     {
         MessageBox.Show("主密码错误");
     }
     loadSubPass();
 }
Esempio n. 6
0
 private void btnChpwd_Click(object sender, EventArgs e)
 {
     if (Form1.cryptor.verifyPassword(FrmInputPassword.Input(this, "请输入旧密码")))
     {
         savepassword = FrmInputPassword.CreatePassword(this);
         if (null == savepassword)
         {
             return;
         }
         appSettingObject.subpasswords.Clear();
         Form1.cryptor.init(savepassword);
         Form1.cryptor.setData(JsonConvert.SerializeObject(appSettingObject), savepassword);
     }
     else
     {
         MessageBox.Show("主密码错误");
     }
     loadSubPass();
 }
Esempio n. 7
0
        private void btnSetting_Click(object sender, EventArgs e)
        {
            string password = FrmInputPassword.Input(this, "请输入密码");

            if (cryptor.verifyPassword(password))
            {
                openSetting(password);
                return;
            }
            else
            {
                password = testSubPassword(password);
                if (password != "")
                {
                    openSetting(password);
                    return;
                }
            }
            MessageBox.Show("密码错误");
        }
Esempio n. 8
0
        private void btnSecurityCheck_Click(object sender, EventArgs e)
        {
            string password = FrmInputPassword.Input(this, "请输入密码");

            if (!cryptor.verifyPassword(password))
            {
                password = testSubPassword(password);
            }
            if (!cryptor.verifyPassword(password))
            {
                MessageBox.Show("密码错误");
                return;
            }
            if (cryptor.verifyData(password))
            {
                MessageBox.Show("数据校验成功,可以放心使用");
            }
            else
            {
                MessageBox.Show("数据校验失败,名单可能已经被篡改", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }