示例#1
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Sure ?", "Warning", MessageBoxButton.YesNo) == MessageBoxResult.No)
            {
                return;
            }
            try
            {
                XElement element = _main._RTaccount.Root.Element("Users");
                foreach (XElement el in element.Descendants("User"))
                {
                    if (el.Element("name").Value == txUserName.Text)
                    {
                        MessageBox.Show("Add failed, \nDuplicated User Name", "Error");
                        return;
                    }
                }

                _main._RTaccount.Root.Element("Users").Add(
                    new XElement("User",
                                 new XElement("name", txUserName.Text),
                                 new XElement("password", CryptorEngine.Encrypt(txPassword.Password, true)),
                                 new XElement("mail", txEmail.Text),
                                 new XElement("role", CbRoleSelected.SelectedItem),
                                 new XElement("AutoLogoutTime", this.txAutologoutTime.Text)
                                 ));

                _main._RTaccount.Save(_main.XmlFile);
                CommFeature.Instance.UpdateRTXml();
                MessageBox.Show("Add Success", "Warning");
                Update();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Add failed, \n" + ex.Message, "Error");
            }
        }
        public User AuthenticateUser(string username, string clearTextPassword)
        {
            InternalUserData userData = _users.FirstOrDefault(u => u.Username.Equals(username) &&
                                                              u.HashedPassword.Equals(CryptorEngine.Encrypt(clearTextPassword, true)));

            if (userData == null)
            {
                throw new UnauthorizedAccessException("Login failed, please check your user id and password.");
            }

            InternalRoleData RoleData = _roles.FirstOrDefault(u => userData.Roles.Contains(u.role));

            return(new User(userData.Username, userData.Email, userData.Roles, userData.AutoLogoutTime, RoleData.pages));
        }