Ejemplo n.º 1
0
        private void buttonRegister_Click(object sender, EventArgs e) {
            if (textBoxUsername.Text.Length == 0) {
                MessageBox.Show("Please choose a username.");
                return;
            }

            if (textBoxPassword.Text.Length == 0) {
                MessageBox.Show("Please choose a password.");
                return;
            }

            var query = from u in db.Users
                        where u.Username == textBoxUsername.Text
                        select u;

            if (query.Count() > 0) {
                MessageBox.Show("That username is already taken.");
            } else {
                try {
                    User user = new User() {
                        Username = textBoxUsername.Text,
                        Password = getHash(textBoxPassword.Text)
                    };

                    db.Users.InsertOnSubmit(user);
                    db.SubmitChanges();

                    MessageBox.Show("Account created. You can now log in.");
                } catch (Exception ex) {
                    MessageBox.Show("Error: " + ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
 public ManagerForm(User user) {
     InitializeComponent();
     labelUsername.Text = user.Username;
 }