コード例 #1
0
ファイル: Default.aspx.cs プロジェクト: yucz/PermissionBase
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        try
        {
            if (Page.IsValid)
            {
                //验证验证码。
                if (tbValidCode.Text != StringSecurity.DESDecrypt(Request.Cookies["AreYouHuman"].Value))
                {
                    panelErrorValidCode.Visible = true;
                    tbPassword.Focus();
                    return;
                }

                //验证登录ID和密码。
                Staff s = StaffSrv.GetStaffByLoginIdAndPassword(tbLoginId.Text.Trim(), tbPassword.Text.Trim());
                if (s == null)
                {
                    panelErrorPassword.Visible = true;
                    tbPassword.Focus();
                    return;
                }
                else
                {
                    if (s.Disabled == 1)//被禁用。
                    {
                        panelStaffDisabled.Visible = true;
                        tbLoginId.Focus();
                        return;
                    }
                }

                //在Cookie中保存登录ID。
                HttpCookie hcLoginId = new HttpCookie("LoginId", s.LoginId);
                hcLoginId.Expires = DateTime.Now.AddMonths(1);
                Response.Cookies.Add(hcLoginId);

                //在Cookie中保存界面样式选择。
                HttpCookie hcInterfaceStyle = new HttpCookie("InterfaceStyle", ddlInterfaceStyle.SelectedValue);
                hcInterfaceStyle.Expires = DateTime.Now.AddMonths(1);
                Response.Cookies.Add(hcInterfaceStyle);

                //保存登录信息。
                SessionUtil.SavaStaffSession(new StaffSession(s.LoginId, s.IsInnerUser));
                FormsAuthentication.RedirectFromLoginPage(s.LoginId, false);

                //登陆成功。
                loginSuccessfully = true;
            }
        }
        catch (Exception ex)
        {
            log.Error(null, ex);
            throw;
        }
    }
コード例 #2
0
ファイル: Form1.cs プロジェクト: 2979261910/hedong
 private void button3_Click(object sender, EventArgs e)
 {
     textBox6.Text = StringSecurity.DESDecrypt(textBox5.Text);
 }