Пример #1
0
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            if (!_users.ContainsKey(username))
            {
                throw new SecurityException("Invalid username");
            }

            XmlMembershipUser user = _users[username];

            return(user);
        }
Пример #2
0
        public override string GetPassword(string username, string answer)
        {
            if (!_users.ContainsKey(username))
            {
                throw new SecurityException("Invalid username");
            }

            XmlMembershipUser user = _users[username];

            return(user.Password);
        }
Пример #3
0
        public override void UpdateUser(MembershipUser user)
        {
            XmlMembershipUser theUser = user as XmlMembershipUser;
            XmlDocument       doc     = new XmlDocument();

            doc.Load(_path);
            XmlNode node = doc.SelectSingleNode(String.Format("//Users/User[@UserName='******']", theUser.UserName));

            if (node == null)
            {
                throw new SecurityException("No such user");
            }

            XmlNode parent = node.ParentNode;

            parent.RemoveChild(node);
            parent.AppendChild(doc.ImportNode(XmlUtils.Serialize(theUser), true));
            doc.Save(_path);
        }
Пример #4
0
        private void ReadData()
        {
            if (_users == null)
            {
                lock (_syncRoot)
                {
                    XmlDocument doc = new XmlDocument();
                    doc.Load(_path);

                    _users = new Dictionary <string, XmlMembershipUser>();
                    foreach (XmlNode node in doc.SelectNodes("//Users/User"))
                    {
                        XmlMembershipUser user = XmlUtils.Deserialize <XmlMembershipUser>(node);
                        if (user.IsApproved)
                        {
                            _users.Add(user.UserName, user);
                        }
                    }
                }
            }
        }
Пример #5
0
        public override bool ValidateUser(string username, string password)
        {
            ReadData();

            if (!_users.ContainsKey(username))
            {
                return(false);
            }

            XmlMembershipUser user = _users[username];

            if (user.PasswordExpired)
            {
                throw new PasswordExpiredException();
            }

            if (!user.Password.Equals(password))
            {
                return(false);
            }

            return(true);
        }