Beispiel #1
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            this.securityMgr = new SecurityMgr(this.systemLog);
            if (this.securityMgr.LanchLogonDlg())
            {
                // get access

                System.Data.SqlClient.SqlConnectionStringBuilder builder =
                    new System.Data.SqlClient.SqlConnectionStringBuilder(Properties.Settings.Default.DetroitConnectionString);
                builder.UserID             = User.Name;
                builder.Password           = User.Password;
                builder.IntegratedSecurity = false;

                Admin.Properties.Settings.ChangeConnectionString(builder.ConnectionString);

                this.systemLog.LogAlert(AlertType.Info, DateTime.Now.ToString() + " --- " + "Admin", "User = "******" --- " + "Admin", "Password = "******" --- " + "Admin", "builder.ConnectionString = " + builder.ConnectionString);
                this.systemLog.LogAlert(AlertType.Info, DateTime.Now.ToString() + " --- " + "Admin", "DetroitConnectionString = " + Properties.Settings.Default.DetroitConnectionString.ToString());

                this.logProvider = new LogProvider(LogType.SQL, Properties.Settings.Default.DetroitConnectionString.ToString(), false);
                this.logProvider.LogAlert(0, "NA", "Admin", this.Name, "User login succesfull.", User.Name);
            }
            else
            {
                // revoke access
                // this.logProvider.LogAlert(0, "", "Application", this.Name, "User login unsuccesfull.", User.Name);
                this.Close();
            };
        }
Beispiel #2
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            var userName = TextBox1.Text.Trim();
            var passWord = TextBox2.Text.Trim();

            //var checkCode = TextBox3.Text.Trim();
            if (string.IsNullOrEmpty(userName))
            {
                TextBox1.Focus();
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入用户名');</script>");
                return;
            }
            if (string.IsNullOrEmpty(passWord))
            {
                TextBox2.Focus();
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入密码');</script>");
                return;
            }
            //if (checkCode != Session[ValidateCode.VALIDATECODEKEY].ToString())
            //{
            //    Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('验证码输入错误');</script>");
            //    TextBox3.Text = "";
            //    TextBox3.Focus();
            //    return;
            //}
            var res = SecurityMgr.Login(userName, passWord);

            if (!string.IsNullOrEmpty(res))
            {
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + res + "');</script>");
            }
            else
            {
                var httpCookie = Request.Cookies["UserName"];
                if (httpCookie != null)
                {
                    var cookName = DotNet.Framework.Common.DEncrypt.DESEncrypt.Decrypt(httpCookie.Value);
                    if (cookName != userName)
                    {
                        var cUserNameStore = new HttpCookie("UserName")
                        {
                            Value = DotNet.Framework.Common.DEncrypt.DESEncrypt.Encrypt(userName)
                        };
                        //var cPassWord = new HttpCookie("PassWord")
                        //    {
                        //        Value = DotNet.Framework.Common.DEncrypt.DESEncrypt.Encrypt(passWord)
                        //    };
                        cUserNameStore.Expires = DateTime.Now.AddDays(30);
                        //cPassWord.Expires = DateTime.Now.AddDays(30);
                        Response.Cookies.Add(cUserNameStore);
                    }
                }
                else
                {
                    var cUserNameStore = new HttpCookie("UserName")
                    {
                        Value = DotNet.Framework.Common.DEncrypt.DESEncrypt.Encrypt(userName)
                    };
                    //var cPassWord = new HttpCookie("PassWord")
                    //    {
                    //        Value = DotNet.Framework.Common.DEncrypt.DESEncrypt.Encrypt(passWord)
                    //    };
                    cUserNameStore.Expires = DateTime.Now.AddDays(30);
                    //cPassWord.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(cUserNameStore);
                }
                //Response.Cookies.Add(cPassWord);
                //if (CheckBox1.Checked)
                //{
                //    var cUserNameStore = new HttpCookie("UserName")
                //        {
                //            Value = DotNet.Framework.Common.DEncrypt.DESEncrypt.Encrypt(userName)
                //        };
                //    var cPassWord = new HttpCookie("PassWord")
                //        {
                //            Value = DotNet.Framework.Common.DEncrypt.DESEncrypt.Encrypt(passWord)
                //        };
                //    cUserNameStore.Expires = DateTime.Now.AddDays(30);
                //    cPassWord.Expires = DateTime.Now.AddDays(30);

                //    Response.Cookies.Add(cUserNameStore);
                //    Response.Cookies.Add(cPassWord);
                //}
                //else
                //{
                //    var httpCookie = Response.Cookies["UserName"];
                //    if (httpCookie != null)
                //        httpCookie.Expires = DateTime.Now.AddSeconds(-1);//Expires过期时间
                //    var cookie = Response.Cookies["PassWord"];
                //    if (cookie != null)
                //        cookie.Expires = DateTime.Now.AddSeconds(-1);//Expires过期时间
                //}
                Response.Redirect("/Manage/Systems/Default.aspx");
            }
        }
Beispiel #3
0
 protected void lbtnLogout_Click(object sender, EventArgs e)
 {
     SecurityMgr.Logoff();
     Response.Redirect("/login.aspx");
 }