Beispiel #1
0
        private void Signin_Click(object sender, RoutedEventArgs e)
        {
            int result = 0;

            try
            {
                Conn.ConnectionString = constring;
                Conn.Open();

                sql = @"select * from u_login(:_useremail,:_password)";
                cmd = new NpgsqlCommand(sql, Conn);
                cmd.Parameters.AddWithValue("_useremail", LoginEmailBox.Text);
                cmd.Parameters.AddWithValue("_password", LoginPasswordBox.Password);
                result = (int)cmd.ExecuteScalar();
            }
            catch
            {
                UseWrongLable("Some kind of data base issue has occured");
            }
            if (result == 1)
            {
                // empty user name is in SQL
                EmptyUser.Email = LoginEmailBox.Text;
                Console.WriteLine(LoginEmailBox.Text);
                MainWindow Main = new MainWindow(EmptyUser);
                Main.Show();
                this.Close();
            }
            else
            {
                try
                {
                    Conn.Close();
                }
                catch
                {
                }
                wrongattemps++;
                LoginPasswordBox.Password = string.Empty;
                UseWrongLable("Wrong info " + (3 - wrongattemps).ToString() + "attempts ");
                if (wrongattemps == 3)
                {
                    UseWrongLable("One more wrong attempt will close the app \n and notify the user");
                }
                if (wrongattemps > 3)
                {
                    User        U  = new User("User", LoginEmailBox.Text);
                    EmailSystem ES = new EmailSystem(U, "Critical issue failed login attempt with yor email");
                    ES.subject = "Login attempt for ";
                    ES.Email();
                    Thread.Sleep(5000);
                    this.Close();
                    //add timer
                }
            }
        }
Beispiel #2
0
        // no code in email yet
        private void Register_Click(object sender, RoutedEventArgs e)
        {
            VerificationComponent VC = new VerificationComponent();
            string m = "";

            if (!VC.IsEmail(EmailBox.Text))
            {
                m = " \n Email in bad format";
            }
            if (VC.Verification(PasswordBox.Text).Contains("Valid") && m == "")
            {
                int result = 0;
                try
                {
                    Conn.ConnectionString = constring;
                    Conn.Open();
                    sql = @"select * from user_table ";
                    cmd = new NpgsqlCommand(sql, Conn);
                    Console.WriteLine(cmd.ExecuteScalar().ToString());
                }
                catch
                {
                    UseWrongLable("database error");
                    Console.WriteLine("database error");
                }
                if (!cmd.ExecuteScalar().ToString().Contains(EmailBox.Text))
                {
                    Conn.Close();
                    EmptyUser = new User(Namebox.Text, EmailBox.Text);
                    GenerationComponent GC = new GenerationComponent();
                    randomcode = GC.GeneratedPassword(15);
                    EmailSystem emailSystem = new EmailSystem(EmptyUser, randomcode);
                    emailSystem.Email();
                    Register.Visibility         = Visibility.Hidden;
                    CodeVerification.Visibility = Visibility.Visible;
                    Wrong.Visibility            = Visibility.Hidden;
                }
                else
                {
                    Conn.Close();
                    UseWrongLable("that email is already registered");
                }
            }
            else
            {
                UseWrongLable(VC.Verification(PasswordBox.Text) + m);
            }
        }