Beispiel #1
0
        /// <summary>
        /// 验证用户名密码是否正确并获取权限
        /// </summary>
        /// <param name="strLoginName">用户名</param>
        /// <param name="strPwd">密码</param>
        /// <returns>用户权限</returns>
        public int Proving(string strLoginName, string strPwd)
        {
            int iComp = 0; // 权限默认为 0

            DataTable dtLogin = MainHelper.BuildLoginTable();

            if (File.Exists(strPath))
            {
                try
                {
                    dtLogin.ReadXml(strPath);

                    DataRow[] drs = dtLogin.Select(" Account = '" + strLoginName + "'");

                    if (drs.Length < 1)
                    {
                        // 提示用户名错误
                        ErrorMessage(3010008, string.Empty, "[FrmLogin:Proving]", Crypt.Decrypt(strLoginName));
                        return(iComp);
                    }

                    for (int i = 0; i < drs.Length; i++)
                    {
                        if (drs[i][1].ToString().Equals(strPwd))
                        {
                            // 获取用户权限
                            iComp = int.Parse(drs[i][2].ToString());
                            return(iComp);
                        }
                    }
                }
                catch
                {
                    // 文件格式不正确
                    ErrorMessage(3010005, string.Empty, "[FrmLogin:Proving]", strPath);
                    return(iComp);
                }

                // 用户名和密码错误
                ErrorMessage(3010009, string.Empty, "[FrmLogin:Proving]", Crypt.Decrypt(strLoginName));
                return(iComp);
            }
            else
            {
                // 没有Login.xml文件
                ErrorMessage(3010006, string.Empty, "[FrmLogin:Proving]", strPath);
                return(iComp);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 读取XML文件
        /// </summary>
        /// <param name="strPath">路径</param>
        /// <returns></returns>
        private DataTable ReadXmlToTable(string strPath)
        {
            DataTable dt = MainHelper.BuildDBConfigTable(strPath);

            try
            {
                dt.ReadXml(strPath); //读取数据库的配置
            }
            catch
            {
                return(dt);
            }

            return(dt);
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="strLoginName">用户名</param>
        /// <param name="strPwd">密码</param>
        /// <param name="strNewPwd">要修改的密码</param>
        /// <returns>是否修改成功</returns>
        public bool UpdatePwd(string strLoginName, string strPwd, string strNewPwd)
        {
            DataTable dtLogin = MainHelper.BuildLoginTable();

            if (File.Exists(strPath))
            {
                try
                {
                    dtLogin.ReadXml(strPath);
                    DataRow[] drs = dtLogin.Select(" Account = '" + strLoginName + "' and Password ='******'");

                    if (drs.Length < 1)
                    {
                        // 提示输入的密码有误
                        ErrorMessage(3010003, string.Empty, "[FrmChangePwd:UpdatePwd]]", frmMain.GetLoginInfo());
                        return(false);
                    }

                    for (int i = 0; i < drs.Length; i++)
                    {
                        // 修改用户密码
                        drs[i][1] = strNewPwd;
                        dtLogin.WriteXml(strPath);

                        // 提示修改成功
                        ErrorMessage(3010004, string.Empty, "[FrmChangePwd:UpdatePwd]", frmMain.GetLoginInfo());
                    }
                    return(true);
                }
                catch
                {
                    // 提示XML文件格式错误
                    ErrorMessage(3010005, string.Empty, "[FrmChangePwd:UpdatePwd]", strPath);
                    return(false);
                }
            }
            else
            {
                // 提示没有该XML文件
                ErrorMessage(3010006, string.Empty, "[FrmChangePwd:UpdatePwd]", strPath);
                return(false);
            }
        }