Ejemplo n.º 1
0
        public override void ViewDidLoad()
        {
            this.applicationDelegate.instructionsShared = 1;

            this.applicationDelegate.passwordLog = this.passwordTextField;
            //this.applicationDelegate.navBar.Frame = new CGRect(0, this.View.Bounds.Top, UIScreen.MainScreen.Bounds.Width, this.applicationDelegate.navBar.Bounds.Height + 20);
            //this.View.AddSubview(this.applicationDelegate.navBar);

            this.NavigationController.SetNavigationBarHidden(false, false);

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            {
                if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight)
                {
                    this.passwordTextField.Frame = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 60.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                    lockImage.Frame = new CGRect(this.View.Center.X - 50.0f, this.View.Center.Y - 50.0f, 100, 100);
                    this.View.AddSubview(lockImage);
                }
                else if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.Portrait || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown)
                {
                    this.passwordTextField.Frame = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 80.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                    lockImage.Frame = new CGRect(this.View.Center.X - 50.0f, this.View.Center.Y - 50.0f, 100, 100);
                    this.View.AddSubview(lockImage);
                }
            }
            else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight)
                {
                    this.passwordTextField.Frame = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 80.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                }
                else if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.Portrait || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown)
                {
                    this.passwordTextField.Frame = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 80.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                }
            }

            this.passwordTextField.EditingChanged += (object sender, EventArgs e) =>
            {
                SystemSound keyboardSound = new SystemSound(1105);
                keyboardSound.PlaySystemSound();
            };

            this.passwordTextField.ReturnKeyType = UIReturnKeyType.Go;

            this.passwordTextField.ShouldReturn += (UITextField textField) => {
                var memoryCache      = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var filePathPassword = System.IO.Path.Combine(memoryCache, "password.txt");

                if (this.passwordTextField.Text != System.IO.File.ReadAllText(filePathPassword))
                {
                    //shared audio player must be set as a play and record setting

                    this.incorrectCount++;
                    if (this.incorrectCount <= 2)
                    {
                        passwordIncorrect("Incorrect password", "Please try again");
                    }
                    else if (this.incorrectCount == 3)
                    {
                        this.incorrectCount = 0;
                        this.passwordTextField.ResignFirstResponder();
                        this.passwordTextField.Text = "\ud83d\udd12 LOCKED";
                        passwordIncorrect("Vault is locked!", "Your vault is locked! You will have to wait 30 seconds for your vault to unlock again");
                        SystemSound alertSound = new SystemSound(1005);
                        if (this.PresentedViewController != null)
                        {
                            for (int i = 0; i <= 10000; i++)
                            {
                                alertSound.PlaySystemSound();
                                this.passwordTextField.UserInteractionEnabled = false;
                                this.passwordTextField.ResignFirstResponder();

                                if (i >= 10000)
                                {
                                    SystemSound unlockVault = new SystemSound(1101);
                                    unlockVault.PlaySystemSound();
                                    this.passwordTextField.Text = "";
                                    this.passwordTextField.UserInteractionEnabled = true;
                                    //passwordIncorrect("Vault is unlocked!", "You can now try to log in again");
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Controller is not yet presented");
                        }
                    }
                }
                else
                {
                    UIStoryboard story_2 = UIStoryboard.FromName("Main", NSBundle.MainBundle);

                    TabMaster vault = story_2.InstantiateViewController("TabMaster") as TabMaster;
                    this.NavigationController.PushViewController(vault, true);
                }
                return(true);
            };

            UIBarButtonItem confirmed = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (sender, e) =>
            {
                var memoryCache      = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                var filePathPassword = System.IO.Path.Combine(memoryCache, "password.txt");

                if (this.passwordTextField.Text != System.IO.File.ReadAllText(filePathPassword))
                {
                    //shared audio player must be set as a play and record setting

                    this.incorrectCount++;
                    if (this.incorrectCount <= 2)
                    {
                        passwordIncorrect("Incorrect password", "Please try again");
                    }
                    else if (this.incorrectCount == 3)
                    {
                        this.incorrectCount = 0;
                        this.passwordTextField.ResignFirstResponder();
                        this.passwordTextField.Text = "\ud83d\udd12 LOCKED";
                        passwordIncorrect("Vault is locked!", "Your vault is locked! You will have to wait 30 seconds for your vault to unlock again");
                        SystemSound alertSound = new SystemSound(1005);
                        if (this.PresentedViewController != null)
                        {
                            for (int i = 0; i <= 10000; i++)
                            {
                                alertSound.PlaySystemSound();
                                this.passwordTextField.UserInteractionEnabled = false;
                                this.passwordTextField.ResignFirstResponder();

                                if (i >= 10000)
                                {
                                    SystemSound unlockVault = new SystemSound(1101);
                                    unlockVault.PlaySystemSound();
                                    this.passwordTextField.Text = "";
                                    this.passwordTextField.UserInteractionEnabled = true;
                                    //passwordIncorrect("Vault is unlocked!", "You can now try to log in again");
                                }
                            }
                        }
                        else
                        {
                            Console.WriteLine("Controller is not yet presented");
                        }
                    }
                }
                else
                {
                    UIStoryboard story_2 = UIStoryboard.FromName("Main", NSBundle.MainBundle);

                    TabMaster vault = story_2.InstantiateViewController("TabMaster") as TabMaster;
                    this.NavigationController.PushViewController(vault, true);
                }
            });

            this.passwordTextField.Placeholder     = "Password";
            this.passwordTextField.ClearButtonMode = UITextFieldViewMode.Always;
            this.passwordTextField.SecureTextEntry = true;
            //this.applicationDelegate.password = this.passwordTextField.Text;

            this.passwordTextField.SpellCheckingType      = UITextSpellCheckingType.No;
            this.passwordTextField.AutocorrectionType     = UITextAutocorrectionType.No;
            this.passwordTextField.AutocapitalizationType = UITextAutocapitalizationType.None;
            this.passwordTextField.BorderStyle            = UITextBorderStyle.RoundedRect;

            this.passwordTextField.Layer.BorderWidth  = 0.2f;
            this.passwordTextField.Layer.BorderColor  = UIColor.Black.CGColor;
            this.passwordTextField.Layer.CornerRadius = 0.2f;

            this.View.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            this.NavigationItem.Title = "Vault Login";
            this.NavigationItem.SetRightBarButtonItem(confirmed, false);


            this.View.AddSubview(passwordTextField);
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            this.lockImage       = new UIImageView(new UIImage("Lock.png"), new UIImage("Lock.png"));
            this.lockImage.Frame = new CGRect(this.View.Center.X - 50.0f, this.View.Center.Y, 100, 100);
            this.View.AddSubview(lockImage);

            this.applicationDelegate.instructionsShared = 0;

            //this.applicationDelegate.navBar.Frame = new CGRect(0, this.View.Bounds.Top, UIScreen.MainScreen.Bounds.Width, this.applicationDelegate.navBar.Bounds.Height + 20);
            //this.View.AddSubview(this.applicationDelegate.navBar);

            this.NavigationController.SetNavigationBarHidden(false, false);

            this.passwordTextField.BorderStyle = UITextBorderStyle.RoundedRect;

            //password confirm properties

            this.passwordConfirmField.BorderStyle = UITextBorderStyle.RoundedRect;

            this.passwordTextField.Placeholder    = "Enter password";
            this.passwordConfirmField.Placeholder = "Confirm password";

            this.passwordTextField.ReturnKeyType    = UIReturnKeyType.Done;
            this.passwordConfirmField.ReturnKeyType = UIReturnKeyType.Done;

            this.passwordTextField.SpellCheckingType      = UITextSpellCheckingType.No;
            this.passwordTextField.AutocorrectionType     = UITextAutocorrectionType.No;
            this.passwordTextField.AutocapitalizationType = UITextAutocapitalizationType.None;

            this.passwordConfirmField.SpellCheckingType      = UITextSpellCheckingType.No;
            this.passwordConfirmField.AutocorrectionType     = UITextAutocorrectionType.No;
            this.passwordConfirmField.AutocapitalizationType = UITextAutocapitalizationType.None;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            {
                if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight)
                {
                    this.passwordConfirmField.Frame = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 140.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                    this.passwordTextField.Frame    = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 60.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                }
                else if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.Portrait || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown)
                {
                    this.passwordConfirmField.Frame = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 160.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                    this.passwordTextField.Frame    = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 80.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                }
            }
            else if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeLeft || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.LandscapeRight)
                {
                    this.passwordConfirmField.Frame = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 140.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                    this.passwordTextField.Frame    = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 80.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                }
                else if (UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.Portrait || UIDevice.CurrentDevice.Orientation == UIDeviceOrientation.PortraitUpsideDown)
                {
                    this.passwordConfirmField.Frame = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 140.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                    this.passwordTextField.Frame    = new CGRect(this.View.Bounds.Left + 5, this.View.Bounds.Top + 80.0f, UIScreen.MainScreen.Bounds.Width - 10.0f, 50);
                }
            }

            this.passwordTextField.EditingChanged += (object sender, EventArgs e) =>
            {
                SystemSound keyboardSound = new SystemSound(1105);
                keyboardSound.PlaySystemSound();
            };

            this.passwordTextField.EditingDidEnd += (object sender, EventArgs e) =>
            {
                if (this.passwordTextField.Text.Length <= 5)
                {
                    if (this.passwordTextField.Text.Length == 0)
                    {
                        //this.passwordTextField.ResignFirstResponder();
                        passwordIncorrect("Passwords do not match", "Your chosen password does not match the confirmed password. Please enter them again and make sure they are equal");
                    }
                    else
                    {
                        passwordIncorrect("Passwords must longer", "Your chosen password needs to be at least 6 characters long. Make sure to include a capital, a few numbers, and at least one symbol. This will make your password more secure");
                    }
                }
            };

            this.passwordConfirmField.EditingDidEnd += (object sender, EventArgs e) =>
            {
                if (this.passwordTextField.Text != this.passwordConfirmField.Text)
                {
                    if (this.PresentedViewController == null)
                    {
                        if (this.passwordConfirmField.Text.Length == 0)
                        {
                            if (this.PresentedViewController == null)
                            {
                                this.passwordConfirmField.ResignFirstResponder();
                                passwordIncorrect("Passwords do not match", "Your chosen password does not match the confirmed password. Please enter them again and make sure they are equal");
                            }
                        }
                        else
                        {
                            passwordIncorrect("Passwords must longer", "Your chosen password needs to be at least 6 characters long. Make sure to include a capital, a few numbers, and at least one symbol. This will make your password more secure");
                        }
                    }
                    else
                    {
                        Console.WriteLine("Controller is already being presented");
                    }
                }
            };

            this.passwordConfirmField.EditingChanged += (object sender, EventArgs e) =>
            {
                SystemSound keyboardSound = new SystemSound(1105);
                keyboardSound.PlaySystemSound();
            };

            this.passwordConfirmField.ShouldReturn += (UITextField textField) =>
            {
                UIStoryboard story_2 = UIStoryboard.FromName("Main", NSBundle.MainBundle);

                TabMaster vault = story_2.InstantiateViewController("TabMaster") as TabMaster;

                if (String.IsNullOrEmpty(this.passwordTextField.Text) == true && String.IsNullOrEmpty(this.passwordConfirmField.Text) == true)
                {
                    passwordIncorrect("Passwords cannot be empty", "Please enter a password and choose something with at least two digits, two characters and at least one capital letter. This will make your password harder to crack");
                }
                else
                {
                    Console.WriteLine("Password entered correctly");

                    if (this.passwordTextField.Text.Length >= 6)
                    {
                        if (this.passwordTextField.Text != this.passwordConfirmField.Text)
                        {
                            passwordIncorrect("Passwords do not match", "Your chosen password does not match the confirmed password. Please enter them again and make sure they are equal");
                        }
                        else
                        {
                            var memoryCache = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                            this.applicationDelegate.logInTitle = this.passwordTextField.Text;
                            var filePathPassword = Path.Combine(memoryCache, "password.txt");
                            File.WriteAllText(filePathPassword, this.passwordTextField.Text);

                            this.NavigationController.PushViewController(vault, true);
                        }
                    }
                    this.passwordTextField.ResignFirstResponder();
                    this.passwordConfirmField.ResignFirstResponder();
                }
                return(true);
            };

            this.passwordTextField.ShouldReturn += (UITextField textField) =>
            {
                UIStoryboard story_2 = UIStoryboard.FromName("Main", NSBundle.MainBundle);

                TabMaster vault = story_2.InstantiateViewController("TabMaster") as TabMaster;

                if (String.IsNullOrEmpty(this.passwordTextField.Text) == true && String.IsNullOrEmpty(this.passwordConfirmField.Text) == true)
                {
                    passwordIncorrect("Passwords cannot be empty", "Please enter a password and choose something with at least two digits, two characters and at least one capital letter. This will make your password harder to crack");
                }
                else
                {
                    Console.WriteLine("Password entered correctly");

                    if (this.passwordTextField.Text.Length >= 6)
                    {
                        if (this.passwordTextField.Text != this.passwordConfirmField.Text)
                        {
                            passwordIncorrect("Passwords do not match", "Your chosen password does not match the confirmed password. Please enter them again and make sure they are equal");
                        }
                        else
                        {
                            var memoryCache = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                            this.applicationDelegate.logInTitle = this.passwordTextField.Text;
                            var filePathPassword = Path.Combine(memoryCache, "password.txt");
                            File.WriteAllText(filePathPassword, this.passwordTextField.Text);

                            this.NavigationController.PushViewController(vault, true);
                        }
                    }
                    this.passwordTextField.ResignFirstResponder();
                    this.passwordConfirmField.ResignFirstResponder();
                }
                return(true);
            };

            this.passwordTextField.SecureTextEntry    = true;
            this.passwordConfirmField.SecureTextEntry = true;

            this.View.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            UIBarButtonItem confirmed = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (sender, e) =>
            {
                UIStoryboard story_2 = UIStoryboard.FromName("Main", NSBundle.MainBundle);

                TabMaster vault = story_2.InstantiateViewController("TabMaster") as TabMaster;

                if (String.IsNullOrEmpty(this.passwordTextField.Text) == true && String.IsNullOrEmpty(this.passwordConfirmField.Text) == true)
                {
                    passwordIncorrect("Passwords cannot be empty", "Please enter a password and choose something with at least two digits, two characters and at least one capital letter. This will make your password harder to crack");
                }
                else
                {
                    Console.WriteLine("Password entered correctly");

                    if (this.passwordTextField.Text.Length >= 6)
                    {
                        if (this.passwordTextField.Text != this.passwordConfirmField.Text)
                        {
                            passwordIncorrect("Passwords do not match", "Your chosen password does not match the confirmed password. Please enter them again and make sure they are equal");
                        }
                        else
                        {
                            var memoryCache = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                            this.applicationDelegate.logInTitle = this.passwordTextField.Text;
                            var filePathPassword = Path.Combine(memoryCache, "password.txt");
                            File.WriteAllText(filePathPassword, this.passwordTextField.Text);

                            this.NavigationController.PushViewController(vault, true);
                        }
                    }
                    this.passwordTextField.ResignFirstResponder();
                    this.passwordConfirmField.ResignFirstResponder();
                }
            });

            UIBarButtonItem denied = new UIBarButtonItem(UIBarButtonSystemItem.Refresh, (sender, e) =>
            {
                passwordTextField.Text    = "";
                passwordConfirmField.Text = "";
            });

            this.NavigationItem.SetRightBarButtonItem(confirmed, false);
            this.NavigationItem.SetLeftBarButtonItem(denied, false);

            this.NavigationItem.Title = "Choose your password";

            this.View.AddSubview(this.passwordTextField);
            this.View.AddSubview(this.passwordConfirmField);
        }