Exemplo n.º 1
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            if (!IsValid)
            {
                return;
            }

            bool      useIntegrated;
            SqlServer server;

            SqlAdmin.Security security = new SqlAdmin.Security();

            if (AuthRadioButtonList.SelectedItem.Value == "windows")
            {
                if (security.WebServer == "iis" && System.Security.Principal.WindowsIdentity.GetCurrent().Name != this.UsernameTextBox.Text)
                {
                    ErrorLabel.Visible = true;
                    ErrorLabel.Text    = "IIS verion of SQL Web Admin doesn't support windows logins other than your own.<br>";
                }

                try {
                    server        = new SqlServer(ServerTextBox.Text, this.UsernameTextBox.Text, this.PasswordTextBox.Text, true);
                    useIntegrated = true;
                }
                catch (System.ComponentModel.Win32Exception w32Ex) {
                    ErrorLabel.Visible = true;
                    ErrorLabel.Text    = "Invalid username and/or password, or server does not exist.";
                    return;
                }
                catch (Exception ex) {
                    ErrorLabel.Visible = true;
                    ErrorLabel.Text    = ex.Message;
                    return;
                }
            }
            else
            {
                server        = new SqlServer(ServerTextBox.Text, UsernameTextBox.Text, PasswordTextBox.Text, false);
                useIntegrated = false;
            }

            if (server.IsUserValid())
            {
                if (useIntegrated)
                {
                    AdminUser.CurrentUser = new AdminUser(UsernameTextBox.Text, PasswordTextBox.Text, ServerTextBox.Text, true);

                    security.WriteCookieForFormsAuthentication(
                        server.Username,
                        server.Password,
                        false,
                        SqlLoginType.NTUser);
                }
                else
                {
                    AdminUser.CurrentUser = new AdminUser(UsernameTextBox.Text, PasswordTextBox.Text, ServerTextBox.Text, false);

                    security.WriteCookieForFormsAuthentication(
                        server.Username,
                        server.Password,
                        false,
                        SqlLoginType.Standard);
                }



                Response.Redirect("databases.aspx");
            }
            else
            {
                ErrorLabel.Visible = true;
                ErrorLabel.Text    = "Invalid username and/or password, you are using a windows login that is not your own, or server does not exist.<br>";
            }
        }
        public void Login()
        {
            string servername = ParamsData["servername"];
            string logintype  = ParamsData["logintype"];
            string uid        = "";
            string pwd        = "";

            uid = ParamsData["uid"];
            pwd = ParamsData["pwd"];

            bool      useIntegrated;
            SqlServer server;

            SqlAdmin.Security security = new SqlAdmin.Security();

            if (logintype == "0")
            {
                server        = new SqlServer(servername, uid, pwd, true);
                useIntegrated = true;
            }
            else
            {
                server        = new SqlServer(servername, uid, pwd, false);
                useIntegrated = false;
            }

            if (server.IsUserValid())
            {
                if (useIntegrated)
                {
                    AdminUser.CurrentUser = new AdminUser(servername, uid, pwd, true);
                    security.WriteCookieForFormsAuthentication(server.Username, server.Password, false, SqlLoginType.NTUser);
                }
                else
                {
                    AdminUser.CurrentUser = new AdminUser(servername, uid, pwd, false);
                    security.WriteCookieForFormsAuthentication(
                        server.Username,
                        server.Password,
                        false,
                        SqlLoginType.Standard);
                }

                PutOutData.Add("server", server);

                server.Connect();
                SqlDatabaseCollection databases = server.Databases;
                server.Disconnect();
                DataTable dt = new DataTable();
                dt.Columns.Add("name");
                dt.Columns.Add("encodedname");
                dt.Columns.Add("size");
                for (int i = 0; i < databases.Count; i++)
                {
                    SqlDatabase database = databases[i];
                    dt.Rows.Add(new object[] { database.Name, database.Name, database.Size == -1 ? "Unknown" : String.Format("{0}MB", database.Size) });
                }

                JsonResult = RetSuccess(null, JavaScriptConvert.SerializeObject(dt));
            }
            else
            {
                JsonResult = RetError("数据库连接失败!");
            }
        }
Exemplo n.º 3
0
        protected void LoginButton_Click(object sender, System.EventArgs e)
        {
            if (!IsValid)
                return;

            bool useIntegrated;
            SqlServer server;
            SqlAdmin.Security security = new SqlAdmin.Security();

            if (AuthRadioButtonList.SelectedItem.Value == "windows")
            {
                if (security.WebServer == "iis" && System.Security.Principal.WindowsIdentity.GetCurrent().Name != this.UsernameTextBox.Text)
                {
                    ErrorLabel.Visible = true;
                    ErrorLabel.Text = "IIS verion of SQL Web Admin doesn't support windows logins other than your own.<br>";
                }

                try
                {
                    server = new SqlServer(ServerTextBox.Text, this.UsernameTextBox.Text, this.PasswordTextBox.Text, true);
                    useIntegrated = true;
                }
                catch (System.ComponentModel.Win32Exception w32Ex)
                {
                    ErrorLabel.Visible = true;
                    ErrorLabel.Text = "Invalid username and/or password, or server does not exist.";
                    return;
                }
                catch (Exception ex)
                {
                    ErrorLabel.Visible = true;
                    ErrorLabel.Text = ex.Message;
                    return;
                }
            }
            else
            {
                server = new SqlServer(ServerTextBox.Text, UsernameTextBox.Text, PasswordTextBox.Text, false);
                useIntegrated = false;
            }

            if (server.IsUserValid())
            {
                if (useIntegrated)
                {
                    AdminUser.CurrentUser = new AdminUser(UsernameTextBox.Text, PasswordTextBox.Text, ServerTextBox.Text, true);
                    security.WriteCookieForFormsAuthentication(server.Username, server.Password, false, SqlLoginType.NTUser);
                }
                else
                {
                    AdminUser.CurrentUser = new AdminUser(UsernameTextBox.Text, PasswordTextBox.Text, ServerTextBox.Text, false);
                    security.WriteCookieForFormsAuthentication(
                        server.Username,
                        server.Password,
                        false,
                        SqlLoginType.Standard);
                }
                Response.Redirect("databases.aspx");
            }
            else
            {
                ErrorLabel.Visible = true;
                ErrorLabel.Text = "Invalid username and/or password, you are using a windows login that is not your own, or server does not exist.<br>";
            }
        }