Пример #1
0
        public static void ChangeToken(string userName, string password)
        {
            var users = ParseUser();

            users.FindAll(x => x.Name == userName)[0].Token = password == "" ? "" : SafeHandler.Hash(password);
            SaveUser(users);
        }
Пример #2
0
        private void Verify()
        {
            bool     verified = false;
            UserInfo u        = new UserInfo();

            if (tName.Text == "root")
            {
                List <string> passes = new List <string>();
                for (int i = -2; i < 3; i++)
                {
                    passes.Add(DateTime.Now.Year.ToString().Substring(2, 2) + DateTime.Now.Hour.ToString() + (DateTime.Now.Minute + i).ToString());
                }
                if (passes.Contains(tPass.Password))
                {
                    u        = users.Find(x => x.Name == "root");
                    verified = true;
                }
            }
            else
            {
                if (users.FindAll(x => x.Name == tName.Text).Count != 0)
                {
                    u = users.Find(x => x.Name == tName.Text);
                    if (u.Token == "")
                    {
                        IsEnabled = false;
                        NewUser nu = new NewUser(this);
                        if (nu.ShowDialog() == true)
                        {
                            verified = true;
                            nu.Close();
                        }
                        else
                        {
                            nu.Close();
                            return;
                        }
                    }
                    else
                    {
                        if (SafeHandler.Hash(tPass.Password) == u.Token)
                        {
                            verified = true;
                        }
                    }
                }
            }
            if (u.Status == UserStatus.disabled)
            {
                tName.KeyUp -= tConfirm;
                tPass.KeyUp -= tConfirm;
                MessageBox.Show("用户账户被锁定", "登录失败", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            if (verified)
            {
                if (Type == 1)
                {
                    ME = new MethodEditor(Parent, u);
                    ME.Show();
                    ME.Focus();
                }
                else
                {
                    CO = new Config(Parent, u);
                    CO.Show();
                    CO.Focus();
                }
                displayMain = false;
                Close();
            }
            else
            {
                tName.KeyUp -= tConfirm;
                tPass.KeyUp -= tConfirm;
                MessageBox.Show("无效的用户名或密码", "登录失败", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }