Пример #1
0
        /// <summary>
        /// Loads and returns a ParentalControlsCredentialsFile.
        /// </summary>
        /// <param name="filename">File to load</param>
        /// <returns>ParentalControlsCredentialsFile with FileName.</returns>
        public static ParentalControlsCredentialsFile Load(string filename)
        {
            ParentalControlsCredentialsFile file = new ParentalControlsCredentialsFile();

            file.FileName = filename;
            try
            {
                using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.OpenOrCreate)))
                {
                    ParentalControlsCredential cred = new ParentalControlsCredential();
                    int readat = 0;
                    while (reader.BaseStream.Position < reader.BaseStream.Length)
                    {
                        switch (readat)
                        {
                        case 0:
                            cred.Username = reader.ReadString();
                            readat        = 1;
                            break;

                        case 1:
                            cred.HashedPassword = reader.ReadString();
                            readat = 0;
                            file.Add(cred);
                            cred = new ParentalControlsCredential();
                            break;
                        }
                    }
                }
            }
            catch { }
            return(file);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem != null)
            {
                ParentalControlsCredential cred = new ParentalControlsCredential(textBox1.Text, textBox2.Text, false);
                if(!file.Remove((ParentalControlsCredential)comboBox1.SelectedItem))
                {
                    TaskDialog dialog = new TaskDialog();

                    dialog.Caption = this.Text;
                    dialog.InstructionText = "Failed to Change Credential";
                    dialog.Text = "An unknown error occured while changing \""+((ParentalControlsCredential)comboBox1.SelectedItem).Username+"\"";
                    dialog.Opened += (a, b) =>
                    {
                        dialog.Icon = TaskDialogStandardIcon.Error;
                    };

                    dialog.Show();
                }
                else
                {
                    file.Add(cred);
                    RefreshItems(false);
                    comboBox1.SelectedItem = cred;
                }
            }
        }
Пример #3
0
 public bool Exists(ParentalControlsCredential cred)
 {
     foreach (ParentalControlsCredential c in _ParentalControlsCredentials)
     {
         //Console.WriteLine("Username: {0} Password: {1}", cred.Username, cred.HashedPassword);
         if (cred.Username == c.Username)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #4
0
 public bool Validate(ParentalControlsCredential parentalControlsCredential)
 {
     //Console.WriteLine("Username: {0} Password: {1}", parentalControlsCredential.Username, parentalControlsCredential.HashedPassword);
     foreach (ParentalControlsCredential cred in _ParentalControlsCredentials)
     {
         //Console.WriteLine("Username: {0} Password: {1}", cred.Username, cred.HashedPassword);
         if (cred.ValidateCredentials(parentalControlsCredential))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #5
0
 /// <summary>
 /// Validates a credential passed with this.
 /// </summary>
 /// <param name="cred">The credential to validate.</param>
 /// <returns>Is the credential valid?</returns>
 public bool ValidateCredentials(ParentalControlsCredential cred)
 {
     //Console.WriteLine("CredA: {0} CredB: {1}", this.ToString(), cred.ToString());
     return (cred.Username == Username && cred.HashedPassword == HashedPassword);
 }
Пример #6
0
 public bool Validate(ParentalControlsCredential parentalControlsCredential)
 {
     //Console.WriteLine("Username: {0} Password: {1}", parentalControlsCredential.Username, parentalControlsCredential.HashedPassword);
     foreach (ParentalControlsCredential cred in _ParentalControlsCredentials)
     {
         //Console.WriteLine("Username: {0} Password: {1}", cred.Username, cred.HashedPassword);
         if (cred.ValidateCredentials(parentalControlsCredential))
         {
             return true;
         }
     }
     return false;
 }
Пример #7
0
 public bool Remove(ParentalControlsCredential cred)
 {
     return Remove(cred.Username);
 }
Пример #8
0
 public bool Exists(ParentalControlsCredential cred)
 {
     foreach (ParentalControlsCredential c in _ParentalControlsCredentials)
     {
         //Console.WriteLine("Username: {0} Password: {1}", cred.Username, cred.HashedPassword);
         if (cred.Username == c.Username)
         {
             return true;
         }
     }
     return false;
 }
Пример #9
0
 public void Add(ParentalControlsCredential ParentalControlsCredential)
 {
     _ParentalControlsCredentials.Add(ParentalControlsCredential);
 }
Пример #10
0
 /// <summary>
 /// Loads and returns a ParentalControlsCredentialsFile.
 /// </summary>
 /// <param name="filename">File to load</param>
 /// <returns>ParentalControlsCredentialsFile with FileName.</returns>
 public static ParentalControlsCredentialsFile Load(string filename)
 {
     ParentalControlsCredentialsFile file = new ParentalControlsCredentialsFile();
     file.FileName = filename;
     try
     {
         using (BinaryReader reader = new BinaryReader(new FileStream(filename, FileMode.OpenOrCreate)))
         {
             ParentalControlsCredential cred = new ParentalControlsCredential();
             int readat = 0;
             while (reader.BaseStream.Position < reader.BaseStream.Length)
             {
                 switch (readat)
                 {
                     case 0:
                         cred.Username = reader.ReadString();
                         readat = 1;
                         break;
                     case 1:
                         cred.HashedPassword = reader.ReadString();
                         readat = 0;
                         file.Add(cred);
                         cred = new ParentalControlsCredential();
                         break;
                 }
             }
         }
     }
     catch { }
     return file;
 }
Пример #11
0
        public void FirstInstall()
        {
            Enable(false);
            RegistryKey reg = ParentalControlsRegistry.GetRegistryKey();
            reg.SetValue("Path", Application.StartupPath, RegistryValueKind.String);
            reg.SetValue("AlarmFile", Application.StartupPath + @"\" + ALARMS_FILE);

            TaskDialog dialog = new TaskDialog();

            dialog.Caption = Application.ProductName+" Setup";
            dialog.InstructionText = Application.ProductName+" is mostly setup!";
            dialog.Text = "What you need to do is setup a password for any cases that you need to force close an alarm.";

            TaskDialogButton button = new TaskDialogButton("btnOne", "Continue");
            button.Click += (aa, ab) =>
            {
                TaskDialogButton tdb = (TaskDialogButton)aa;
                ((TaskDialog)tdb.HostingDialog).Close(TaskDialogResult.Ok);

                if (file2.ParentalControlsCredentials.Count > 0)
                {
                    TaskDialog dadialog = new TaskDialog();
                    dadialog.InstructionText = "Setup Complete!";
                    dadialog.Text = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();

                    return;
                }

                NetworkCredential cred = null;
                WindowsSecurity.GetCredentialsVistaAndUp("Please enter new credentials for Parental Controls", "Set username and password for stopping an alarm.", out cred);
                while (cred == null || (string.IsNullOrWhiteSpace(cred.UserName) || string.IsNullOrWhiteSpace(cred.Password)))
                {
                    WindowsSecurity.GetCredentialsVistaAndUp("Please enter new credentials for Parental Controls", "Set username and password for stopping an alarm. (Credentials must not be empty)", out cred);
                }
                ParentalControlsCredential c;
                try
                {
                    c = (ParentalControlsCredential)cred;
                    c.HashedPassword = SHA256Hash.Hash(c.HashedPassword);
                    file2.Add(c);
                    file2.Save();
                }
                catch {  }
                TaskDialog ndialog = new TaskDialog();
                ndialog.Caption = Application.ProductName + " Setup";
                ndialog.InstructionText = "Want to test your credentials?";
                ndialog.FooterText = "Fun Fact: You can create as many accounts as you want!";
                ndialog.FooterIcon = TaskDialogStandardIcon.Information;

                TaskDialogCommandLink linka = new TaskDialogCommandLink("linkA", "Test Credentials");

                linka.Click += (ba, bb) =>
                {
                    TaskDialogButton tb = (TaskDialogButton)ba;
                    ((TaskDialog)tb.HostingDialog).Close(TaskDialogResult.Yes);

                    WindowsSecurity.GetCredentialsVistaAndUp("Please enter credentials for \"Parental Controls\"", "Force disabling \"TestAlarm\"", out cred);
                    c = new ParentalControlsCredential();
                    try
                    {
                        c = (ParentalControlsCredential)cred;
                        c.HashedPassword = SHA256Hash.Hash(c.HashedPassword);
                    }
                    catch { }

                    bool wevalidated = true;

                    while (cred == null || !file2.Validate(c) || (string.IsNullOrWhiteSpace(cred.UserName) || string.IsNullOrWhiteSpace(cred.Password)))
                    {
                        TaskDialog ddialog = new TaskDialog();

                        ddialog.InstructionText = "Credentials Invalid";
                        ddialog.Text = "You want to stop testing credentials?";

                        ddialog.StandardButtons = TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No;

                        if (ddialog.Show() == TaskDialogResult.Yes)
                        {
                            wevalidated = false;
                            break;
                        }
                        else
                            WindowsSecurity.GetCredentialsVistaAndUp("Please enter credentials for \"Parental Controls\"", "Force disabling \"TestAlarm\"", out cred);
                    }
                    TaskDialog dadialog = new TaskDialog();
                    if (wevalidated)
                    {
                        dadialog.InstructionText = "Credentials Valid!";
                    }
                    else
                    {
                        dadialog.InstructionText = "Setup Complete!";
                    }
                    dadialog.Text = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();
                };

                TaskDialogCommandLink linkb = new TaskDialogCommandLink("linkB", "Skip Test");

                linkb.Click += (ba, bb) =>
                {
                    TaskDialogButton tb = (TaskDialogButton)ba;
                    ((TaskDialog)tb.HostingDialog).Close(TaskDialogResult.No);

                    TaskDialog dadialog = new TaskDialog();
                    dadialog.InstructionText = "Setup Complete!";
                    dadialog.Text = "You are now done setting up Parental Controls!";

                    dadialog.StandardButtons = TaskDialogStandardButtons.Ok;
                    dadialog.Show();
                };

                ndialog.Controls.Add(linka);
                ndialog.Controls.Add(linkb);

                ndialog.Show();
                file2.Save();
            };
            dialog.Controls.Add(button);

            dialog.Show();
            Enable(true);
            // Kind of an hacky way of making this window get focused after showing dialogs.
            SwitchToSelf();
        }
Пример #12
0
 /// <summary>
 /// Validates a credential passed with this.
 /// </summary>
 /// <param name="cred">The credential to validate.</param>
 /// <returns>Is the credential valid?</returns>
 public bool ValidateCredentials(ParentalControlsCredential cred)
 {
     //Console.WriteLine("CredA: {0} CredB: {1}", this.ToString(), cred.ToString());
     return(cred.Username == Username && cred.HashedPassword == HashedPassword);
 }
Пример #13
0
 public void Add(ParentalControlsCredential ParentalControlsCredential)
 {
     _ParentalControlsCredentials.Add(ParentalControlsCredential);
 }
Пример #14
0
 public bool Remove(ParentalControlsCredential cred)
 {
     return(Remove(cred.Username));
 }