Beispiel #1
0
        private void LoginForm_Load(object sender, EventArgs e)
        {
            this.textBoxUser.Text = "admin";
            //this.textBoxUser.Text = "xxx";

            StoredData users;
            bool       firstRun = !StoredData.LoadUserList(StoredData.FileName, out users);

            if (!firstRun)
            {
                StoredData = users;
            }
            else
            {
                StoredData ui = StoredData.CreateFirstRunStoredData();
                ui.SaveToFile(StoredData.FileName);
                StoredData.LoadUserList(StoredData.FileName, out users);
                StoredData = users;
            }
        }
Beispiel #2
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string userName = textBoxUser.Text;
            string password = textBoxPassword.Text;

            if (StoredData.Admin.Name.Equals(userName))
            {
                if (StoredData.Admin.Password == null)
                {
                    ChangePasswordForm cpf = new ChangePasswordForm();
                    cpf.ShowDialog();

                    if (cpf.DialogResult != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }

                    StoredData.Admin.Password = cpf.Password;
                    StoredData.SaveToFile(StoredData.FileName);

                    // start as admin
                    CurrentUser         = StoredData.Admin;
                    AuthenticationState = AuthenticationStates.Admin;
                    this.Close();
                }

                if (StoredData.Admin.Password.Equals(password))
                {
                    // start as admin
                    CurrentUser         = StoredData.Admin;
                    AuthenticationState = AuthenticationStates.Admin;
                    this.Close();
                }
                else
                {
                    TreatIncorrectPassword();
                }
                return;
            }

            if (StoredData.Users.Any(u => u.Name.Equals(userName)))
            {
                UserInfo user = StoredData.Users.First(u =>
                                                       u.Name.Equals(userName));



                if (user.Password == null)
                {
                    if (user.Blocked)
                    {
                        MessageBox.Show("the user name is blocked.");
                        return;
                    }

                    ChangePasswordForm cpf = new ChangePasswordForm();
                    cpf.UserInfo = user as UserInfo;
                    cpf.ShowDialog();

                    if (cpf.DialogResult != System.Windows.Forms.DialogResult.OK)
                    {
                        return;
                    }

                    user.Password = cpf.Password;
                    StoredData.SaveToFile(StoredData.FileName);

                    // start as the selected user
                    CurrentUser         = user;
                    AuthenticationState = AuthenticationStates.User;
                    this.Close();
                }


                if (user.Password.Equals(password))
                {
                    if (user.Blocked)
                    {
                        MessageBox.Show("the user name is blocked.");
                        return;
                    }

                    // start as the selected user
                    CurrentUser         = user;
                    AuthenticationState = AuthenticationStates.User;
                    this.Close();
                }
                else
                {
                    TreatIncorrectPassword();
                }
                return;
            }

            MessageBox.Show("Username doesn't exist. Please try again");
        }
Beispiel #3
0
        static void CreateTestFile()
        {
            StoredData ui = StoredData.CreateTestUserList();

            ui.SaveToFile(StoredData.FileName);
        }