Example #1
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            bool        match = false;
            FilePrep    prep  = new FilePrep();
            List <User> users = new List <User>(prep.ReadUser(Resource1.UserDataFile));
            User        user  = new User(UsernameTextBox.Text, PasswordTextBox.Text);

#if DEBUG
            HashCode hash = delegate(string pw) { return(HashPw(pw)); };
#endif

#if DEBUG_SERVICE
            HashService.HashServiceClient client = new HashService.HashServiceClient();
            HashCode hash = delegate(string pw) { return(client.HashPassword(pw)); };
#endif

            foreach (User u in users)
            {
                if (u.Username == user.Username && Int32.Parse(u.Password) == hash(user.Password))
                {
                    MainMenu menu = new MainMenu(u);
                    match = true;
                    menu.Show();
                }
            }
            if (!match)
            {
                MessageBox.Show(Resource1.WrongLoginData);
            }
        }
Example #2
0
        private void RegisterButton_Click(object sender, EventArgs e)
        {
            FilePrep            prep  = new FilePrep();
            Lazy <List <User> > users = new Lazy <List <User> >(() => new List <User>(prep.ReadUser(Resource1.UserDataFile)));

            if (checkBox18.Checked)
            {
                if (PasswordTextBox.Text == RepeatPassword.Text)
                {
                    bool match = false;
                    User user  = new User(usernameTextBox.Text, PasswordTextBox.Text);
                    foreach (User u in users.Value)
                    {
                        if (u.Username.Equals(user.Username))
                        {
                            MessageBox.Show(Resource1.UsernameTaken);
                            match = true;
                            break;
                        }
                    }
                    if (!match)
                    {
                        IHashService hash;
                        HashService.HashServiceClient client = new HashService.HashServiceClient();

                        if (client != null)
                        {
                            hash = new HashNonLocal();
                        }
                        else
                        {
                            hash = new HashLocal();
                        }

                        prep.Write(Resource1.UserDataFile, user, hash);
                        MessageBox.Show(Resource1.UserCreated);
                        Close();
                    }
                }
                else
                {
                    MessageBox.Show(Resource1.PasswordsDontMatch);
                }
            }
            else
            {
                MessageBox.Show(Resource1.AgeDenied);
            }
        }