Esempio n. 1
0
        private void Save_Click(object sender, RoutedEventArgs e)
        {
            if (txUserName.Text == string.Empty)
            {
                MessageBox.Show("Please input user name", "Warning"); return;
            }
            else if (txPassword.Password == string.Empty)
            {
                MessageBox.Show("Please input password", "Warning"); return;
            }

            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)
                    {
                        el.Remove();
                        break;
                    }
                }

                _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("Save Success", "Warning");
                Update();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Save 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));
        }