Exemplo n.º 1
0
    public bool Authenticate(string applicationName, string userName, string password)
    {
        if (HttpContext.Current.Request.IsSecureConnection == false)
        {
            HttpContext.Current.Trace.Warn("You should use HTTPS to avoid sending passwords in clear text");
        }
        int  token;
        bool authenticated = WindowsSecurity.LogonUser(applicationName, userName, password, out token);

        Token = token;
        return(authenticated);
    }
Exemplo n.º 2
0
 public StatusViewModel() : this(WindowsSecurity.GetUserFullName())
 {
 }
Exemplo n.º 3
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();
        }