webserive 用xml写的 登陆方法

来源:互联网 发布:大富豪棋牌源码 编辑:程序博客网 时间:2024/05/17 05:05
  public string Select(string id,string ps)
        {
            //File.WriteAllText("D:/users/anmj/documents/visual studio 2010/Projects/Bill/Bill/123.xml", Encryption.Encrypt(str));
            string strpath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\XmlData\\UserXml.xml";
            XmlDocument doc = new XmlDocument();
            #region 验证
            try
            {
                if (!File.Exists(strpath))
                {
                    XmlDeclaration xmldeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8","yes");
                    doc.AppendChild(xmldeclaration);
                    XmlElement xmlelement = doc.CreateElement("Users");
                    doc.AppendChild(xmlelement);
                    doc.Save(strpath);
                }
                doc.Load(strpath);
                XmlNodeList node = doc.DocumentElement.SelectNodes("User[@ID=\"" + id + "\"]");
                if (node.Count > 0)
                {
                    foreach (XmlNode item in node)
                    {
                        if ((item as XmlElement).GetAttribute("Password") == Encryption.Encrypt(ps))
                        {
                            Application["User_id"] = (item as XmlElement).GetAttribute("ID");
                            return "Home.aspx";
                        }
                    }
                    return "#";
                }
                else
                    return "#";
            }
            catch
            {
                return "#";
            }
            #endregion
        }
0 0
原创粉丝点击