Ejemplo n.º 1
0
        // Login click
        private void button3_Click(object sender, EventArgs e)
        {
            PasswordBuilder pass;

            if (encrypt_login.SelectedIndex == 0)
            {
                pass = new SHA1Builder(pass_login.Text);
            }
            else
            {
                pass = new SHA256Builder(pass_login.Text);
            }

            pass.GenerateBytes();
            pass.GenerateHashBytes();
            pass.GenerateHashString();

            active_user = _service.GetUser(user_login.Text, pass.GetPassword().HashString);

            if (active_user == null)
            {
                MessageBox.Show("Wrong user or password.", "OK");
            }
            else
            {
                MessageBox.Show("Successful login.", "OK");
            }

            user_login.Text             = "";
            pass_login.Text             = "";
            encrypt_login.SelectedIndex = 0;

            if (active_user != null)
            {
                panel2.Visible = false;
                panel1.Visible = false;

                user_main.Text  = active_user.Username;
                email_main.Text = active_user.Email;

                if (active_user.Cities != "")
                {
                    user_cities = GetUserCities(active_user);
                }
            }
        }
Ejemplo n.º 2
0
        // Register click
        private void button1_Click(object sender, EventArgs e)
        {
            if (user_reg.Text == "" | email_reg.Text == "" | pass_reg.Text == "")
            {
                MessageBox.Show("Please, complete all the fealds.", "OK");
                user_reg.Text             = "";
                email_reg.Text            = "";
                pass_reg.Text             = "";
                encrypt_reg.SelectedIndex = 0;
                return;
            }

            // Validate email
            string m = email_reg.Text;

            var mail = new ValidateMailClass(new ValidateMailAt(), m);

            if (mail.Validate())
            {
                mail = new ValidateMailClass(new ValidateMailDomain(), m);
                if (!mail.Validate())
                {
                    MessageBox.Show("Wrong email adress.", "OK");
                    user_reg.Text             = "";
                    email_reg.Text            = "";
                    pass_reg.Text             = "";
                    encrypt_reg.SelectedIndex = 0;
                    return;
                }
            }
            else
            {
                MessageBox.Show("Wrong email adress.", "OK");
                user_reg.Text             = "";
                email_reg.Text            = "";
                pass_reg.Text             = "";
                encrypt_reg.SelectedIndex = 0;
                return;
            }

            // Validate username
            if (_service.VerifyUser(user_reg.Text, email_reg.Text))
            {
                MessageBox.Show("Username or email are already taken.", "OK");
                user_reg.Text             = "";
                email_reg.Text            = "";
                pass_reg.Text             = "";
                encrypt_reg.SelectedIndex = 0;
                return;
            }

            // Password encryption
            PasswordBuilder pass;

            if (encrypt_reg.SelectedIndex == 0)
            {
                pass = new SHA1Builder(pass_reg.Text);
            }
            else
            {
                pass = new SHA256Builder(pass_reg.Text);
            }

            pass.GenerateBytes();
            pass.GenerateHashBytes();
            pass.GenerateHashString();

            User u = new User {
                Username = user_reg.Text, Email = email_reg.Text, Password = pass.GetPassword().HashString, Cities = "", Passtype = encrypt_reg.SelectedIndex
            };

            string result = _service.AddUser(u);

            MessageBox.Show(result, "OK");

            user_reg.Text             = "";
            email_reg.Text            = "";
            pass_reg.Text             = "";
            encrypt_reg.SelectedIndex = 0;

            panel1.Visible = true;
        }