Ejemplo n.º 1
0
        /// <summary>
        /// 注册用户
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuRegiste_Click(object sender, EventArgs e)
        {
            UserRegistForm frmReg = new UserRegistForm();

            if (frmReg.ShowDialog() == DialogResult.OK)
            {
                if (frmReg.Password != frmReg.OkPassword)
                {
                    ShowWarningMessageBox("密码填写错误");
                    frmReg.Password   = "";
                    frmReg.OkPassword = "";
                    return;
                }
                else if (frmReg.UserName == "")
                {
                    ShowWarningMessageBox("用户名不能为空");
                }
                else
                {
                    string strMi    = Encryption_Decryption.MingToMi(frmReg.OkPassword);
                    string userName = frmReg.UserName;
                    //经用户添加到数据库中
                    if (AddUserToDB(userName, strMi))
                    {
                        MessageBox.Show("注册用户成功", "恭喜");
                        //为新用户赋予相应权限
                        HavePermission();
                    }
                }
            }
        }
        //加密操作 utf-8码
        public static String MingToMi(string strMing)
        {
            byte[] byteArrMi = Encryption_Decryption.EncryptString(
                Encoding.UTF8.GetBytes(strMing));
            string strMi = Encoding.UTF8.GetString(byteArrMi);

            return(strMi);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void menuLogin_Click(object sender, EventArgs e)
        {
            LoginForm frmLogin = new LoginForm();

            if (frmLogin.ShowDialog() == DialogResult.OK)
            {
                string userName = frmLogin.UserName;
                string password = frmLogin.PassWord;
                string MiPwd    = Encryption_Decryption.MingToMi(password);
                string sql      = string.Format("select count(*) from [tb_User] where name='{0}'and pwd='{1}'",
                                                userName, MiPwd);
                SqlConnection connection = ConnDataBase.connection;
                try
                {
                    connection.Open();
                    SqlCommand command = new SqlCommand(sql, connection);
                    //执行查询语句,发挥匹配的行数
                    int num = (int)command.ExecuteScalar();
                    if (num > 0)
                    {
                        frmLogin.Close();
                        //获得相应权限
                        HavePermission();
                        //保存到当前用户
                        CurUser = userName;
                        if (!frmLogin.DicNameCode.ContainsKey(frmLogin.UserName) &&
                            frmLogin.CkRememberNameCode.Checked == true)
                        {
                            frmLogin.WriteNameCodeToXml(frmLogin.UserName, frmLogin.PassWord);
                        }
                        MessageBox.Show("恭喜您,成功登录", "信息提示",
                                        MessageBoxButtons.OKCancel,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        frmLogin.PassWord = "";
                        MessageBox.Show("您输入的用户名或密码错误!", "登录失败",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "操作数据库出错", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                finally
                {
                    connection.Close();
                }
            }
        }