Ejemplo n.º 1
0
        private void edtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            edtInvalid.Visible = false;
            int validLogon = 1;

            try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (DBase.AutoLogOn != "1")
                    {
                        validLogon = 0;
                    }

                    if (DWindow.ValidateLogOn(edtUserName.Text, edtPassword.Text) || (validLogon == 0 && AllowBlankPass == 0 && DHuy.HideFood(edtPassword.Text, "justicenzy", new byte[64]) == DBase.PasswordAuthen))
                    {
                        allowClose = 1;

                        if (edtUserName.Text != Environment.UserName) // Logon to other user
                        {
                            int errorInProcess = 0;
                            try
                            {
                                DBase.RegistrySetLM("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", "AutoRestartShell", "0", true);
                                DBase.RegistrySetLM("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", "ForceAutoLogon", "1", true);

                                DBase.RegistrySetLM("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", "DefaultDomainName", Environment.MachineName);
                                DBase.RegistrySetLM("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", "DefaultUserName", edtUserName.Text);
                                DBase.RegistrySetLM("Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon", "AutoAdminLogon", "1");

                                RegEncryption R = new RegEncryption("DefaultPassword"); R.SetSecret(edtPassword.Text);
                                DBase.AutoLogOn = "1";
                                DBase.SaveSetting();
                            }
                            catch (Exception ex)
                            {
                                errorInProcess = 1;
                            }

                            if (errorInProcess == 0) // everything ok --> auto logon log off
                            {
                                DBase.AutoLogOnUser_AfterLogOff(edtUserName.Text, edtPassword.Text);
                                this.Close();
                            }
                            else
                            {
                                edtInvalid.Text    = "Account permision deny!";
                                edtInvalid.Visible = true;
                            }
                        }
                        else //same user logon
                        {
                            //   Process.Start("Explorer");
                            this.Close();
                        }
                    }
                    else
                    {
                        edtPassword.Text   = "";
                        edtInvalid.Text    = "Invalid authencation !";
                        edtInvalid.Visible = true;
                    }
                }
            }
            catch (Exception ex)
            {
                // MessageBox.Show(ex.ToString());
            }
        }