private void button1_Click(object sender, EventArgs e)
        {
            RegistryKey MyReg0, RegGUIDFlag, RegFlag, RegValidGUIDDays, RegValidDays, RegStartGUIDDate, RegStartDate, RegPassword;

            MyReg0 = Registry.CurrentUser;

            //删除原有注册表项
            MyReg0.DeleteSubKeyTree("Identities\\{D46B7C02-B796-4AAA-9D4F-2188CF2DBA30}", false);
            MyReg0.DeleteSubKeyTree("Software\\Aurora", false);

            try
            {
                RegGUIDFlag = MyReg0.CreateSubKey("Identities\\{D46B7C02-B796-4AAA-9D4F-2188CF2DBA30}");
                RegFlag     = MyReg0.CreateSubKey("Software\\Aurora");

                RegValidGUIDDays = MyReg0.CreateSubKey("Identities\\{D46B7C02-B796-4AAA-9D4F-2188CF2DBA30}");
                RegValidDays     = MyReg0.CreateSubKey("Software\\Aurora");

                RegStartGUIDDate = MyReg0.CreateSubKey("Identities\\{D46B7C02-B796-4AAA-9D4F-2188CF2DBA30}");
                RegStartDate     = MyReg0.CreateSubKey("Software\\Aurora");

                RegFlag.SetValue("nRegFlag", "0");
                RegValidDays.SetValue("nValidDays", "10");
                RegGUIDFlag.SetValue("nRegGUIDFlag", "0");
                RegValidGUIDDays.SetValue("nValidGUIDDays", "10");
                RegStartGUIDDate.SetValue("StartGUIDDate", DateTime.Now.ToString("yyyy-MM-dd"));
                RegStartDate.SetValue("StartDate", DateTime.Now.ToString("yyyy-MM-dd"));

                RegPassword = MyReg0.CreateSubKey("Software\\Aurora\\Locker");
                RegPassword.SetValue("Password", "000");
                //Application.Restart();
            }
            catch { }
        }
        private void textBox1_Leave(object sender, EventArgs e)             //判断输入密码和原来的密码
        {
            if (textBox1.Text == "")
            {
                pictureBox1.Visible = false;
            }
            string      strPassword = "";
            RegistryKey MyReg1, RegPassword;

            MyReg1      = Registry.CurrentUser;
            RegPassword = MyReg1.CreateSubKey("Software\\Aurora\\Locker");
            try
            {
                strPassword = RegPassword.GetValue("Password").ToString();
            }
            catch { }

            if (textBox1.Text == strPassword)       // || textBox1.Text == "Administrator")
            {
                pictureBox1.Visible = true;
                pictureBox1.Image   = Properties.Resources.Right;
                Flag1            = 1;
                textBox2.Enabled = true;
                textBox3.Enabled = true;
            }
            else
            {
                pictureBox1.Visible = true;
                pictureBox1.Image   = Properties.Resources.Wrong;
                //MessageBox.Show("原密码输入错误", "Aurora智能提示");
                textBox2.Enabled = false;
                textBox3.Enabled = false;
            }
        }
        private void button1_Click(object sender, EventArgs e)              //确认
        {
            RegistryKey MyReg1, RegPassword;

            MyReg1      = Registry.CurrentUser;
            RegPassword = MyReg1.CreateSubKey("Software\\Aurora\\Locker");

            string strPassword = textBox3.Text;
            string strShowText = textBox4.Text;

            if (Flag1 == 1 && Flag2 == 1 && textBox3.Text != "")               //将修改后的密码写入本地ini文件
            {
                try
                {
                    RegPassword.SetValue("Password", strPassword);
                }
                catch { }
            }

            if (textBox4 != null)
            {
                try
                {
                    RegPassword.SetValue("ShowText", strShowText);
                }
                catch { }
            }

            this.Close();
        }
        private void Locker_Activated(object sender, EventArgs e)               //旧坐标需要在此获取
        {
            if (Thread.CurrentThread.CurrentUICulture.ToString() == "zh-CN")
            {
                this.Text = "Aurora智能数据锁 ● 正在积极的保护您的数据";
            }
            else if (Thread.CurrentThread.CurrentUICulture.ToString() == "zh-Hant")
            {
                this.Text = "Aurora智慧資料鎖 ● 正在積極的保護您的資料";
            }
            else //if (Thread.CurrentThread.CurrentUICulture.ToString() == "en")
            {
                this.Text = "Aurora Intelligent Data Locker ● is Protecting Your Data Positively";
            }

            PreviousX = Control.MousePosition.X;
            PreviousY = Control.MousePosition.Y;

            RegistryKey MyReg1, RegPassword;

            MyReg1      = Registry.CurrentUser;
            RegPassword = MyReg1.CreateSubKey("Software\\Aurora\\Locker");
            try
            {
                label1.Text = RegPassword.GetValue("ShowText").ToString();
            }
            catch { }
        }
 private void RegConfirmPassword_Validating(object sender, CancelEventArgs e)
 {
     {
         if (this.RegConfirmPassword.Text != this.RegPassword.Text)
         {
             this.errorProvider1.SetError(this.RegConfirmPassword, "Password and Confirm must be the same");
             e.Cancel = true;
             RegPassword.Clear();
             RegConfirmPassword.Clear();
         }
         else
         {
             this.errorProvider1.SetError(this.RegConfirmPassword, "");
         }
     }
 }
Пример #6
0
        private void button1_Click(object sender, EventArgs e)      //和注册表Locker\\Password对比,一样可以退出。
        {
            string      strPassword = "";
            RegistryKey MyReg1, RegPassword;

            MyReg1      = Registry.CurrentUser;
            RegPassword = MyReg1.CreateSubKey("Software\\Aurora\\Locker");
            try
            {
                strPassword = RegPassword.GetValue("Password").ToString();
            }
            catch { }

            if (textBox1.Text == strPassword)       // || textBox1.Text == "Administrator")
            {
                this.Close();
                PublicClass.Locker.Hide();
                PublicClass.AuroraMain.Show();
                PublicClass.AuroraMain.Activate();              //为毛焦点不能到主窗体上去。退出Locker后按任意键仍然弹出密码框。
                PublicClass.AuroraMain.WindowState = FormWindowState.Normal;

                System.Windows.Forms.Cursor.Show(); //显示鼠标
            }
            else
            {
                if (Thread.CurrentThread.CurrentUICulture.ToString() == "zh-CN")
                {
                    label1.Text = "输入密码不正确,请重新输入。";
                }
                else if (Thread.CurrentThread.CurrentUICulture.ToString() == "zh-Hant")
                {
                    label1.Text = "輸入密碼不正確,請重新輸入。";
                }
                else //if (Thread.CurrentThread.CurrentUICulture.ToString() == "en")
                {
                    label1.Text = "Incorrect password, please try again.";
                }
                textBox1.Clear();
                textBox1.Focus();
            }
        }
        private void StdReg_Click(object sender, EventArgs e)
        {
            try
            {
                //从用户名文本框获取字符串给用户名变量赋值
                string userName = RegUserName.Text;

                //从密码文本框获取字符串给密码变量赋值
                string password = RegPassword.Text;

                //从姓名文本框获取字符串给姓名变量赋值
                string name = RegName.Text;

                //从班级文本框获取字符串给班级变量赋值
                string className = RegClass.Text;

                //从学号文本框获取字符串给学号变量赋值
                string cardID = RegCardID.Text;

                //利用正则表达式判断各文本框内的值是否符合要求
                if (Regex.IsMatch(userName, @"^[a-zA-Z][a-zA-Z0-9_]{4,15}$") == false)
                {
                    MessageBox.Show("用户名只能由英文和数字组成,长度为5-16个字节");
                }
                else if (Regex.IsMatch(password, @"^[a-zA-Z0-9]\w{5,17}$") == false)
                {
                    MessageBox.Show("密码以字母开头,长度在6~18之间,只能包含字母、数字和下划线");
                }
                else if (Regex.IsMatch(name, @"^[\u4e00-\u9fa5]+$") == false)
                {
                    MessageBox.Show("姓名只能为中文");
                }
                else if (Regex.IsMatch(className, @"^[0-9]+$") == false || Regex.IsMatch(cardID, @"^[0-9]+$") == false)
                {
                    MessageBox.Show("班级和卡号只能为数字");
                }
                else
                {
                    //用户输入的都符合要求

                    //先判断用户名和学号是否重复
                    string selectSQL = "select * from StdInfo where UserName='******' or CardID='" + cardID + "'";

                    DataSet ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, selectSQL);

                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        //有重复的
                        MessageBox.Show("用户名或学号已被注册");
                    }
                    else
                    {
                        RegUserName.Clear();
                        RegPassword.Clear();
                        RegName.Clear();
                        RegClass.Clear();
                        RegCardID.Clear();
                        //没有重复的

                        //将用户输入的密码进行加盐哈希处理
                        password = PasswordSecurity.PasswordStorage.CreateHash(RegPassword.Text);

                        //将数据存入数据库
                        string insertSQL = "INSERT INTO StdInfo VALUES ('" + userName + "', '" + password + "', N'" + name + "', '" + className + "','" + cardID + "')";

                        int result = SqlHelper.ExecuteNonQuery(conn, CommandType.Text, insertSQL);
                        if (result > 0)
                        {
                            MessageBox.Show("注册成功,请返回登录");
                        }
                        else
                        {
                            MessageBox.Show("注册失败,请重新注册");
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("注册失败");
            }
        }