示例#1
0
 /// <summary>
 /// 初始化事件
 /// </summary>
 private void InitEvent()
 {
     this.tbAccount.Leave += new EventHandler(delegate(object sender, EventArgs args)
     {
         if (Common.TextBoxChecked(tbAccount))
         {
             this.lbAccount.Text = "√";
         }
         else
         {
             this.lbAccount.Text = "x none content";
             //this.tbAccount.Focus();
         }
     });
     this.tbPwd.Leave += new EventHandler(delegate(object sender, EventArgs args)
     {
         if (Common.TextBoxChecked(tbPwd))
         {
             this.lbPwd.Text = "√";
         }
         else
         {
             this.lbPwd.Text = "x none content";
             //this.tbPwd.Focus();
         }
     });
 }
示例#2
0
 private void OK()
 {
     if (Common.TextBoxChecked(this.tbPwd) && Common.TextBoxChecked(this.tbNewPwd) &&
         Common.TextBoxChecked(this.tbConfirm) && Common.PasswordConfirmed(tbNewPwd, tbConfirm) && tbNewPwd.Text.TrimEnd() != Common.User.Pwd)
     {
         Common.User.Pwd = this.tbNewPwd.Text.TrimEnd();
         Common.User.LastPwdChangedTime = DateTime.Now;
         UserInfoBLL _bll = new UserInfoBLL();
         if (_bll.UdateUser(Common.User))
         {
             Utils.ShowMessageBox(Messages.ResetPasswordSuccessfully, Messages.TitleNotification);
             Undo();
             //记录成功的日志
             if (Common.User.UserName != Common.SUPERUSER)
             {
                 logBll.InsertLog(() =>
                 {
                     Dictionary <string, object> dic = new Dictionary <string, object>();
                     dic.Add("OperateTime", DateTime.UtcNow);
                     dic.Add("Action", LogAction.ChangePassword);
                     dic.Add("UserName", Common.User.UserName);
                     dic.Add("FullName", Common.User.FullName);
                     dic.Add("Detail", Common.User.UserName);
                     dic.Add("LogType", LogAction.SystemAuditTrail);
                     return(dic);
                 });
             }
         }
         else
         {
             Utils.ShowMessageBox(Messages.ResetPasswordFailed, Messages.TitleError);
         }
         //form.Close();
     }
 }
示例#3
0
 private void OK()
 {
     if (Common.TextBoxChecked(this.tbPwd) && Common.TextBoxChecked(this.tbNewPwd) &&
            Common.TextBoxChecked(this.tbConfirm) && Common.PasswordConfirmed(tbNewPwd, tbConfirm))
     {
         Common.User.Pwd = this.tbNewPwd.Text.TrimEnd();
         if (processor == null)
             processor = new DeviceProcessor();
         if (processor.Update<UserInfo>(Common.User, null))
             MessageBox.Show("Change Successfully.");
         else
             MessageBox.Show("Change Failure.");
         form.Close();
     }
 }
示例#4
0
 private bool Confirm()
 {
     try
     {
         if (Common.TextBoxChecked(tbAccount) && Common.TextBoxChecked(tbPwd))
         {
             UserInfo user = _userBll.GetUserInfoByUsername(tbAccount.Text.Trim());
             if (user != null && user.Userid != 0)
             {
                 int day = (DateTime.Now.Date - user.LastPwdChangedTime.Date).Days;
                 if (day < Common.Policy.PwdExpiredDay || Common.Policy.PwdExpiredDay == 0)
                 {
                     if (user.Pwd == tbPwd.Text.Trim() && user.Locked == 0 && user.Disabled == 0)
                     {
                         username = user.UserName;
                         fullname = user.FullName;
                         return(true);
                     }
                     if (user.Locked == 1)
                     {
                         Utils.ShowMessageBox(Messages.UserLocked, Messages.TitleError);
                         return(false);
                     }
                 }
                 else
                 {
                     Utils.ShowMessageBox(Messages.PasswordExpired, Messages.TitleError);
                     return(false);
                 }
             }
             Utils.ShowMessageBox(Messages.WrongUserNameOrPassword, Messages.TitleError);
             return(false);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
示例#5
0
 private void OK()
 {
     if (Common.TextBoxChecked(this.tbPwd) && Common.TextBoxChecked(this.tbNewPwd) &&
         Common.TextBoxChecked(this.tbConfirm) && Common.PasswordConfirmed(tbNewPwd, tbConfirm))
     {
         Common.User.Pwd = this.tbNewPwd.Text.TrimEnd();
         if (processor == null)
         {
             processor = new DeviceProcessor();
         }
         if (processor.Update <UserInfo>(Common.User, null))
         {
             MessageBox.Show(Messages.ChangeNewPasswordOk, Messages.TitleNotification);
         }
         else
         {
             MessageBox.Show(Messages.ChangeNewPasswordFailed, Messages.TitleError);
         }
         form.Close();
     }
 }
示例#6
0
        private void InitEventsForTextBoxValidation()
        {
            this.tbPwd.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbPwd))
                {
                    //判断密钥长度
                    if (Common.Policy == null)
                    {
                        Common.ClearToolTip(this.wrongTip, this.pbPasswordTip);
                    }
                    else
                    {
                        if (tbPwd.Text.TrimEnd().Length >= Common.Policy.MinPwdSize)
                        {
                            Common.ClearToolTip(this.wrongTip, this.pbPasswordTip);
                        }
                        else
                        {
                            this.pbPasswordTip.Visible = true;
                            this.wrongTip.SetToolTip(this.pbPasswordTip, string.Format(Messages.PasswordShortThanDefined, Common.Policy.MinPwdSize));
                        }
                    }
                }
                else
                {
                    this.pbPasswordTip.Visible = true;
                    this.wrongTip.SetToolTip(this.pbPasswordTip, Messages.EmptyContentError);
                }
            });
            /*密码确认*/
            this.tbConfirm.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbConfirm))
                {
                    if (Common.PasswordConfirmed(tbPwd, tbConfirm))
                    {
                        Common.ClearToolTip(this.wrongTip, this.pbConfirmPasswordTip);
                    }
                    else
                    {
                        this.pbConfirmPasswordTip.Visible = true;
                        this.wrongTip.SetToolTip(this.pbConfirmPasswordTip, Messages.MismatchPassword);
                    }
                }
                else
                {
                    this.pbConfirmPasswordTip.Visible = true;
                    this.wrongTip.SetToolTip(this.pbConfirmPasswordTip, Messages.EmptyContentError);
                }
            });

            this.tbFullName.Leave += new EventHandler((sender, args) => {
                if (Common.TextBoxChecked(this.tbFullName))
                {
                    Common.ClearToolTip(this.wrongTip, this.pbFullNameTip);
                }
                else
                {
                    this.pbFullNameTip.Visible = true;
                    this.wrongTip.SetToolTip(this.pbFullNameTip, Messages.EmptyContentError);
                }
            });

            this.tbDescription.Leave += new EventHandler((sender, args) =>
            {
                if (Common.TextBoxChecked(this.tbDescription))
                {
                    Common.ClearToolTip(this.wrongTip, this.pbRoleTip);
                }
                else
                {
                    this.pbRoleTip.Visible = true;
                    this.wrongTip.SetToolTip(this.pbRoleTip, Messages.EmptyContentError);
                }
            });
        }
示例#7
0
        private void OK()
        {
            string message = this.checkAllUserInfoFields();

            if (!string.IsNullOrEmpty(message))
            {
                Utils.ShowMessageBox(message, Messages.TitleError);
                return;
            }
            if (Common.TextBoxChecked(this.tbUserName) && Common.TextBoxChecked(this.tbFullName) &&
                Common.TextBoxChecked(this.tbDescription) && Common.TextBoxChecked(this.tbPwd) &&
                Common.TextBoxChecked(this.tbConfirm) && Common.PasswordConfirmed(tbPwd, tbConfirm))
            {
                /*密钥长度*/
                if (Common.Policy == null || Common.Policy.MinPwdSize > this.tbPwd.Text.Length)
                {
                    return;
                }

                bool isChangeGroup = false, isChangePwd = false, isEditUser = false, isDisableUser = false;
                /*记录日志*/
                if (user.RoleId != Convert.ToInt32(this.cbxRole.SelectedValue))
                {
                    isChangeGroup = true;
                }
                if (user.Pwd != tbPwd.Text)
                {
                    isChangePwd = true;
                }
                if (user.Description != tbDescription.Text || user.FullName != tbFullName.Text)
                {
                    isEditUser = true;
                }
                if (isChangePwd || isChangeGroup || isEditUser || isDisableUser)
                {
                    if (username == string.Empty)
                    {
                        user.Userid = ++userid;
                    }
                    user.Account            = this.tbUserName.Text.TrimEnd();
                    user.FullName           = this.tbFullName.Text.TrimEnd();
                    user.Description        = this.tbDescription.Text.TrimEnd();
                    user.LastPwdChangedTime = this.tbPwd.Text == user.Pwd ? user.LastPwdChangedTime : DateTime.Now;
                    user.Pwd    = this.tbPwd.Text.TrimEnd();
                    user.Remark = DateTime.Now.ToString();
                    user.RoleId = this.cbxRole.SelectedValue == null ? 1 : Convert.ToInt32(this.cbxRole.SelectedValue);
                    if (processor.InsertOrUpdate <UserInfo>(user, null, username == string.Empty ? true : false))
                    {
                        Utils.ShowMessageBox(Messages.SavedSuccessfully, Messages.TitleNotification);
                        if (isChangeGroup)
                        {
                            InsertChangeLog("Change group");
                        }
                        if (isChangePwd)
                        {
                            InsertChangeLog("Change password");
                        }
                        if (isEditUser)
                        {
                            InsertChangeLog("Edit user");
                        }
                        if (isDisableUser && user.Disabled != 0)
                        {
                            InsertChangeLog("Disable user");
                        }
                        form.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        Utils.ShowMessageBox(Messages.SavedFailed, Messages.TitleError);
                        form.DialogResult = DialogResult.No;
                    }
                }
                else
                {
                    form.DialogResult = DialogResult.OK;
                }
            }
        }
示例#8
0
        private void InitEvents()
        {
            /*关闭窗口*/
            this.btnCancel.Click += new EventHandler(delegate(object sender, EventArgs args)
            {
                this.form.Close();
            });
            this.tbPwd.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbPwd))
                {
                    if (this.tbPwd.Text.TrimEnd() == Common.User.Pwd)
                    {
                        this.lbAlarmPwd.Text = "√ correct password.";
                    }
                    else
                    {
                        this.tbPwd.Focus();
                        this.lbAlarmPwd.Text = "x wrong password.";
                    }
                }
                else
                {
                    this.tbPwd.Focus();
                    this.lbAlarmPwd.Text = "x none content.";
                }
            });
            /*新密码校验*/
            this.tbNewPwd.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbNewPwd))
                {
                    //判断密钥长度
                    if (Common.Policy == null)
                    {
                        this.lbAlarmNewPwd.Text = "√";
                    }
                    else
                    {
                        if (tbNewPwd.Text.TrimEnd().Length >= Common.Policy.MinPwdSize)
                        {
                            if (tbNewPwd.Text.TrimEnd() != Common.User.Pwd)
                            {
                                this.lbAlarmNewPwd.Text = "√";
                            }
                            else
                            {
                                this.lbAlarmNewPwd.Text = "x same as current.";
                                this.tbNewPwd.Focus();
                            }
                        }
                        else
                        {
                            this.lbAlarmNewPwd.Text = "x min pwd size is " + Common.Policy.MinPwdSize.ToString();
                            this.tbNewPwd.Focus();
                        }
                    }
                }
                else if (!Common.TextBoxChecked(tbNewPwd))
                {
                    this.tbNewPwd.Focus();
                    this.lbAlarmNewPwd.Text = "x none content";
                }

                if (Common.PasswordConfirmed(tbNewPwd, tbConfirm))
                {
                    this.lbAlarmConfirm.Text = "√";
                }
            });
            /*密码确认*/
            this.tbConfirm.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbConfirm))
                {
                    if (Common.PasswordConfirmed(tbNewPwd, tbConfirm))
                    {
                        this.lbAlarmConfirm.Text = "√";
                    }
                    else
                    {
                        this.lbAlarmConfirm.Text = "x confirmed failure";
                    }
                }
                else
                {
                    this.tbConfirm.Focus();
                    this.lbAlarmConfirm.Text = "x none content";
                }
            });
            /*保存修改后的密码*/
            this.btnOK.Click += new EventHandler(delegate(object sender, EventArgs args)
            {
                OK();
            });
            /*确认密码回车*/
            this.tbConfirm.KeyPress += new KeyPressEventHandler(delegate(object sender, KeyPressEventArgs args)
            {
                if (args.KeyChar == 13)
                {
                    OK();
                }
            });
        }
示例#9
0
        private void InitEvent()
        {
            this.Load += new EventHandler(delegate(object sender, EventArgs args) { this.tbUserName.Focus(); });
            #region username
            this.tbUserName.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked((TextBox)sender))
                {
                    //判断用户名是否使用过
                    UserInfo user = processor.QueryOne <UserInfo>("select * from userinfo where username=@username", delegate()
                    {
                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic.Add("username", tbUserName.Text);
                        return(dic);
                    });
                    if (user.Userid == 0)
                    {
                        lbAlarmUn.Text = "√";
                    }
                    else
                    {
                        this.lbAlarmUn.Text  = "x " + tbUserName.Text + " has been used";
                        this.tbUserName.Text = "";
                        //this.tbUserName.Focus();
                    }
                }
                else
                {
                    //this.tbUserName.Focus();
                    this.lbAlarmUn.Text = "x none content";
                }
            });
            #endregion
            #region fullname
            this.tbFullName.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked((TextBox)sender))
                {
                    this.lbAlarmFN.Text = "√";
                }
                else
                {
                    //this.tbFullName.Focus();
                    this.lbAlarmFN.Text = "x none content";
                }
            });
            #endregion
            #region desc
            this.tbDescription.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbDescription))
                {
                    this.lbAlarmDesc.Text = "√";
                }
                else
                {
                    //this.tbDescription.Focus();
                    this.lbAlarmDesc.Text = "x none content";
                }
            });
            #endregion
            #region pwd
            this.tbPwd.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbPwd))
                {
                    //判断密钥长度
                    if (Common.Policy == null)
                    {
                        this.lbAlarmPwd.Text = "√";
                    }
                    else
                    {
                        if (tbPwd.Text.TrimEnd().Length >= Common.Policy.MinPwdSize)
                        {
                            this.lbAlarmPwd.Text = "√";
                        }
                        else
                        {
                            this.lbAlarmPwd.Text = "x min pwd size is " + Common.Policy.MinPwdSize.ToString();
                            //this.tbPwd.Focus();
                        }
                    }
                }
                else if (!Common.TextBoxChecked(tbPwd))
                {
                    //this.tbPwd.Focus();
                    this.lbAlarmPwd.Text = "x none content";
                }

                if (Common.PasswordConfirmed(tbPwd, tbConfirm))
                {
                    this.lbAlarmConfirm.Text = "√";
                }
            });
            #endregion
            #region confirm
            this.tbConfirm.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbConfirm))
                {
                    if (Common.PasswordConfirmed(tbPwd, tbConfirm))
                    {
                        this.lbAlarmConfirm.Text = "√";
                    }
                    else
                    {
                        this.lbAlarmConfirm.Text = "x confirmed failure";
                    }
                }
                else
                {
                    //this.tbConfirm.Focus();
                    this.lbAlarmConfirm.Text = "x none content";
                }
            });
            #endregion
        }
示例#10
0
        private void InitEvent()
        {
            this.Load += new EventHandler(delegate(object sender, EventArgs args) {
                this.tbUserName.Focus();
                if (FirstCreate)
                {
                    this.parentForm.FormTitleText = InputBoxTitle.WizardCreateAdmin;
                }
                this.rbUser.Enabled  = !FirstCreate;
                this.rbAdmin.Checked = FirstCreate;
                this.rbUser.Checked  = !FirstCreate;
            });
            #region username
            this.tbUserName.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                ((TextBox)sender).Text = ((TextBox)sender).Text.Trim();
                if (Common.TextBoxChecked((TextBox)sender))
                {
                    //判断用户名是否使用过
                    UserInfo user = processor.QueryOne <UserInfo>("select * from userinfo where username=@username COLLATE NOCASE", delegate()
                    {
                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic.Add("username", tbUserName.Text.Trim().ToLower());
                        return(dic);
                    });
                    if (user.Userid == 0)
                    {
                        Common.ClearToolTip(this.wrongTip, this.pbUserNameTip);
                    }
                    else
                    {
                        Common.SetToolTip(this.wrongTip, this.pbUserNameTip, Messages.UserNameOccupied);
                    }
                }
                else
                {
                    Common.SetToolTip(this.wrongTip, this.pbUserNameTip, Messages.EmptyContentError);
                }
            });
            #endregion
            #region fullname
            this.tbFullName.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked((TextBox)sender))
                {
                    Common.ClearToolTip(this.wrongTip, this.pbFullNameTip);
                }
                else
                {
                    Common.SetToolTip(this.wrongTip, this.pbFullNameTip, Messages.EmptyContentError);
                }
            });
            #endregion
            #region desc
            this.tbDescription.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbDescription))
                {
                    Common.ClearToolTip(this.wrongTip, this.pbRoleTip);
                }
                else
                {
                    Common.SetToolTip(this.wrongTip, this.pbRoleTip, Messages.EmptyContentError);
                }
            });
            #endregion
            #region pwd
            this.tbPwd.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbPwd))
                {
                    //判断密钥长度
                    if (Common.Policy == null)
                    {
                        Common.ClearToolTip(this.wrongTip, this.pbPasswordTip);
                    }
                    else
                    {
                        if (tbPwd.Text.TrimEnd().Length >= Common.Policy.MinPwdSize)
                        {
                            Common.ClearToolTip(this.wrongTip, this.pbPasswordTip);
                        }
                        else
                        {
                            Common.SetToolTip(this.wrongTip, this.pbPasswordTip, string.Format(Messages.PasswordShortThanDefined, Common.Policy.MinPwdSize));
                        }
                    }
                }
                else
                {
                    Common.SetToolTip(this.wrongTip, this.pbPasswordTip, Messages.EmptyContentError);
                }
            });
            #endregion
            #region confirm
            this.tbConfirm.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbConfirm))
                {
                    if (Common.PasswordConfirmed(tbPwd, tbConfirm))
                    {
                        Common.ClearToolTip(this.wrongTip, this.pbConfirmPasswordTip);
                    }
                    else
                    {
                        Common.SetToolTip(this.wrongTip, this.pbConfirmPasswordTip, Messages.MismatchPassword);
                    }
                }
                else
                {
                    Common.SetToolTip(this.wrongTip, this.pbConfirmPasswordTip, Messages.EmptyContentError);
                }
            });
            #endregion

            this.initGroupRadioCheckEvent();
            //非法字符处理事件
            this.tbUserName.TextChanged += new EventHandler((sender, e) => {
                Utils.IsInputTextValid(this.tbUserName);
            });
            this.tbFullName.TextChanged += new EventHandler((sender, e) =>
            {
                Utils.IsInputTextValid(this.tbFullName);
            });
        }
示例#11
0
        private void InitEvents()
        {
            this.btnOK.Click += new EventHandler(delegate(object sender, EventArgs args){
                if (Common.TextBoxChecked(this.tbUserName) /*&& Common.TextBoxChecked(this.tbFullName) &&
                                                            * Common.TextBoxChecked(this.tbDescription)*/&& Common.TextBoxChecked(this.tbPwd) &&
                    Common.TextBoxChecked(this.tbConfirm) && Common.PasswordConfirmed(tbPwd, tbConfirm))
                {
                    /*密钥长度*/
                    if (Common.Policy == null || Common.Policy.MinPwdSize > this.tbPwd.Text.Length)
                    {
                        return;
                    }
                    if (username == string.Empty)
                    {
                        user.Userid = ++userid;
                    }
                    user.Account            = this.tbUserName.Text.TrimEnd();
                    user.FullName           = this.tbFullName.Text.TrimEnd();
                    user.Description        = this.tbDescription.Text.TrimEnd();
                    user.LastPwdChangedTime = this.tbPwd.Text == user.Pwd ? user.LastPwdChangedTime : DateTime.Now;
                    user.Pwd       = this.tbPwd.Text.TrimEnd();
                    user.Locked    = this.cbLocked.Checked == true ? 1 : 0;
                    user.ChangePwd = this.cbChangePwd.Checked == true ? 1 : 0;
                    user.Remark    = DateTime.Now.ToString();
                    user.RoleId    = this.cbxRole.SelectedValue == null ? 1: Convert.ToInt32(this.cbxRole.SelectedValue);
                    if (processor.InsertOrUpdate <UserInfo>(user, null, username == string.Empty ? true : false))
                    {
                        MessageBox.Show("Saved Successfully");
                        form.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        MessageBox.Show("Saved Failure");
                        form.DialogResult = DialogResult.No;
                    }
                }
            });
            this.btnCancel.Click += new EventHandler(delegate(object sender, EventArgs args){
                form.Close();
            });
            this.tbUserName.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked((TextBox)sender))
                {
                    //判断用户名是否使用过
                    UserInfo user = processor.QueryOne <UserInfo>("select * from userinfo where username=@username", delegate() {
                        Dictionary <string, object> dic = new Dictionary <string, object>();
                        dic.Add("username", tbUserName.Text);
                        return(dic);
                    });
                    if (user.Userid == 0)
                    {
                        lbAlarmUn.Text = "√";
                    }
                    else
                    {
                        this.lbAlarmUn.Text = "x " + tbUserName.Text + " has been used";
                        this.tbUserName.Focus();
                    }
                }
                else
                {
                    this.tbUserName.Focus();
                    this.lbAlarmUn.Text = "x none content";
                }
            });
            this.tbFullName.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked((TextBox)sender))
                {
                    this.lbAlarmFN.Text = "√";
                }
                else
                {
                    //this.tbFullName.Focus();
                    this.lbAlarmFN.Text = "x none content";
                }
            });
            this.tbDescription.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbDescription))
                {
                    this.lbAlarmDesc.Text = "√";
                }
                else
                {
                    //this.tbDescription.Focus();
                    this.lbAlarmDesc.Text = "x none content";
                }
            });
            this.tbPwd.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbPwd))
                {
                    //判断密钥长度
                    if (Common.Policy == null)
                    {
                        this.lbAlarmPwd.Text = "√";
                    }
                    else
                    {
                        if (tbPwd.Text.TrimEnd().Length >= Common.Policy.MinPwdSize)
                        {
                            this.lbAlarmPwd.Text = "√";
                        }
                        else
                        {
                            this.lbAlarmPwd.Text = "x min pwd size is " + Common.Policy.MinPwdSize.ToString();
                            //this.tbPwd.Focus();
                        }
                    }
                }
                else if (!Common.TextBoxChecked(tbPwd))
                {
                    //this.tbPwd.Focus();
                    this.lbAlarmPwd.Text = "x none content";
                }

                if (Common.PasswordConfirmed(tbPwd, tbConfirm))
                {
                    this.lbAlarmConfirm.Text = "√";
                }
            });
            this.tbConfirm.Leave += new EventHandler(delegate(object sender, EventArgs args)
            {
                if (Common.TextBoxChecked(tbConfirm))
                {
                    if (Common.PasswordConfirmed(tbPwd, tbConfirm))
                    {
                        this.lbAlarmConfirm.Text = "√";
                    }
                    else
                    {
                        this.lbAlarmConfirm.Text = "x confirmed failure";
                    }
                }
                else
                {
                    //this.tbConfirm.Focus();
                    this.lbAlarmConfirm.Text = "x none content";
                }
            });
        }
示例#12
0
 /// <summary>
 /// 判断是否登录成功,同时保存用户信息
 /// </summary>
 /// <returns></returns>
 public bool Login()
 {
     try
     {
         if (Common.TextBoxChecked(tbAccount) && Common.TextBoxChecked(tbPwd))
         {
             UserInfo user = processor.QueryOne <UserInfo>("SELECT * FROM UserInfo WHERE username=@username", delegate()
             {
                 Dictionary <string, object> dic = new Dictionary <string, object>();
                 dic.Add("username", tbAccount.Text.TrimEnd());
                 //dic.Add("pwd", tbPwd.Text.TrimEnd());
                 return(dic);
             });
             if (user.Locked == 0)
             {
                 if (LoginTimes <= Common.Policy.LockedTimes)
                 {
                     if (user.Userid != 0 && user.Pwd.Equals(this.tbPwd.Text))
                     {
                         Common.User = user;
                         LoginTimes  = 0;
                         this.SaveUserList();//保存列表
                         //记录成功的日志
                         logBll.InsertLog(() =>
                         {
                             Dictionary <string, object> dic = new Dictionary <string, object>();
                             dic.Add("OperateTime", DateTime.Now);
                             dic.Add("Action", "Log on");
                             dic.Add("UserName", user.UserName);
                             dic.Add("FullName", user.FullName);
                             dic.Add("Detail", "Success");
                             dic.Add("LogType", 0);
                             return(dic);
                         });
                         return(true);
                     }
                     else if (user.Userid == 0)
                     {
                         this.lbAccount.Text = "× user does not exist.";
                         //this.lbAccount.ForeColor = System.Drawing.Color.Red;
                         return(false);
                     }
                     else
                     {
                         this.lbPwd.Text = "× password invalid.";
                         //this.lbPwd.ForeColor = System.Drawing.Color.Red;
                         LoginTimes++;
                         //记录日志
                         logBll.InsertLog(() =>
                         {
                             Dictionary <string, object> dic = new Dictionary <string, object>();
                             dic.Add("OperateTime", DateTime.Now);
                             dic.Add("Action", "Log on");
                             dic.Add("UserName", user.UserName);
                             dic.Add("FullName", user.FullName);
                             dic.Add("Detail", "Failure");
                             dic.Add("LogType", 0);
                             return(dic);
                         });
                         return(false);
                     }
                 }
                 else
                 {
                     Dictionary <string, object> dic = new Dictionary <string, object>();
                     dic.Add("locked", 1);
                     dic.Add("username", this.tbAccount.Text.TrimEnd());
                     processor.ExecuteNonQuery("UPDATE userinfo set locked=@locked where username=@username", dic);
                     this.lbPwd.Text = "× over " + Common.Policy.LockedTimes.ToString() + " times";
                 }
             }
             else
             {
                 this.lbPwd.Text = "× account's locked.";
                 //记录账号锁定日志
                 logBll.InsertLog(() =>
                 {
                     Dictionary <string, object> dic = new Dictionary <string, object>();
                     dic.Add("OperateTime", DateTime.Now);
                     dic.Add("Action", "Log on");
                     dic.Add("UserName", user.UserName);
                     dic.Add("FullName", user.FullName);
                     dic.Add("Detail", "Failure");
                     dic.Add("LogType", 0);
                     return(dic);
                 });
             }
         }
         return(false);
     }
     catch (Exception exc) { return(false); }
 }
示例#13
0
 /// <summary>
 /// 判断是否登录成功,同时保存用户信息
 /// </summary>
 /// <returns></returns>
 public bool Login()
 {
     try
     {
         if (Common.TextBoxChecked(tbAccount) && Common.TextBoxChecked(tbPwd))
         {
             UserInfo user = processor.QueryOne <UserInfo>("SELECT * FROM UserInfo WHERE username=@username COLLATE NOCASE", delegate()
             {
                 Dictionary <string, object> dic = new Dictionary <string, object>();
                 dic.Add("username", tbAccount.Text.Trim().ToLower());
                 //dic.Add("pwd", tbPwd.Text.TrimEnd());
                 return(dic);
             });
             if (user.Locked == 0)
             {
                 if (user.Userid != 0 && user.Pwd.Equals(this.tbPwd.Text) && user.Disabled == 0)
                 {
                     Common.User = user;
                     loginTimes[user.UserName] = 0;
                     this.SaveUserList();    //保存列表
                     //记录成功的日志
                     if (Common.User.UserName != Common.SUPERUSER)
                     {
                         logBll.InsertLog(() =>
                         {
                             Dictionary <string, object> dic = new Dictionary <string, object>();
                             dic.Add("OperateTime", DateTime.UtcNow);
                             dic.Add("Action", LogAction.Logon);
                             dic.Add("UserName", user.UserName);
                             dic.Add("FullName", user.FullName);
                             dic.Add("Detail", "Successful");
                             dic.Add("LogType", LogAction.SystemAuditTrail);
                             return(dic);
                         });
                     }
                     return(true);
                 }
                 else if (user.Userid == 0 || user.Disabled == 1)
                 {
                     //TODO:
                     if (tbAccount.Text == Common.SUPERUSER && tbPwd.Text == Common.SUPERUSERPWD)
                     {
                         UserInfo super = new UserInfo()
                         {
                             UserName           = Common.SUPERUSER,
                             Pwd                = Common.SUPERUSERPWD,
                             FullName           = "super admin",
                             LastPwdChangedTime = DateTime.UtcNow,
                             RoleId             = 1
                         };
                         Common.User = super;
                         return(true);
                     }
                     else
                     {
                         Utils.ShowMessageBox(Messages.WrongUserNameOrPassword, Messages.TitleError);
                         return(false);
                     }
                 }
                 else if (user.Pwd != this.tbPwd.Text)
                 {
                     if (!loginTimes.ContainsKey(user.UserName))
                     {
                         loginTimes[user.UserName] = 0;
                     }
                     loginTimes[user.UserName]++;
                     if (loginTimes[user.UserName] >= Common.Policy.LockedTimes && Common.Policy.LockedTimes > 0)
                     {
                         Dictionary <string, object> dic = new Dictionary <string, object>();
                         dic.Add("locked", 1);
                         dic.Add("username", this.tbAccount.Text.TrimEnd());
                         processor.ExecuteNonQuery("UPDATE userinfo set locked=@locked where username=@username COLLATE NOCASE", dic);
                         Utils.ShowMessageBox(Messages.WrongPasswordExcceedCertainTimes, Messages.TitleError);
                     }
                     else
                     {
                         Utils.ShowMessageBox(Messages.WrongUserNameOrPassword, Messages.TitleError);
                     }
                     //记录账号锁定日志
                     if (Common.User.UserName != Common.SUPERUSER)
                     {
                         logBll.InsertLog(() =>
                         {
                             Dictionary <string, object> dic = new Dictionary <string, object>();
                             dic.Add("OperateTime", DateTime.UtcNow);
                             dic.Add("Action", LogAction.Logon);
                             dic.Add("UserName", user.UserName);
                             dic.Add("FullName", user.FullName);
                             dic.Add("Detail", "Failed");
                             dic.Add("LogType", LogAction.SystemAuditTrail);
                             return(dic);
                         });
                     }
                     return(false);
                 }
                 else
                 {
                     return(false);
                 }
             }
             else
             {
                 Utils.ShowMessageBox(Messages.UserLocked, Messages.TitleError);
             }
         }
         else
         {
             Utils.ShowMessageBox(Messages.WrongUserNameOrPassword, Messages.TitleError);
         }
         return(false);
     }
     catch { return(false); }
 }
示例#14
0
 /// <summary>
 /// 初始化事件
 /// </summary>
 private void InitEvent()
 {
     /*新密码校验*/
     this.tbNewPwd.Leave += new EventHandler(delegate(object sender, EventArgs args)
     {
         if (Common.TextBoxChecked(tbNewPwd))
         {
             //判断密钥长度
             if (Common.Policy == null)
             {
                 Common.ClearToolTip(this.wrongTip, this.pbNewPasswordTip);
             }
             else
             {
                 if (tbNewPwd.Text.TrimEnd().Length >= Common.Policy.MinPwdSize)
                 {
                     if (tbNewPwd.Text.TrimEnd() != Common.User.Pwd)
                     {
                         Common.ClearToolTip(this.wrongTip, this.pbNewPasswordTip);
                     }
                     else
                     {
                         Common.SetToolTip(this.wrongTip, this.pbNewPasswordTip, Messages.NewSameOfOldWhenResetPassword);
                     }
                 }
                 else
                 {
                     Common.SetToolTip(this.wrongTip, this.pbNewPasswordTip, string.Format(Messages.PasswordShortThanDefined, Common.Policy.MinPwdSize));
                 }
             }
         }
         else if (!Common.TextBoxChecked(tbNewPwd))
         {
         }
     });
     /*密码确认*/
     this.tbConfirm.Leave += new EventHandler(delegate(object sender, EventArgs args)
     {
         if (Common.TextBoxChecked(tbConfirm))
         {
             if (Common.PasswordConfirmed(tbNewPwd, tbConfirm))
             {
                 Common.ClearToolTip(this.wrongTip, this.pbConfirmNewPasswordTip);
             }
             else
             {
                 Common.SetToolTip(this.wrongTip, this.pbConfirmNewPasswordTip, Messages.MismatchPassword);
             }
         }
         else
         {
         }
     });
     /*保存修改后的密码*/
     this.btnOK.Click += new EventHandler(delegate(object sender, EventArgs args)
     {
         OK();
     });
     /*确认密码回车*/
     this.tbConfirm.KeyPress += new KeyPressEventHandler(delegate(object sender, KeyPressEventArgs args)
     {
         if (args.KeyChar == 13)
         {
             OK();
         }
     });
     tbNewPwd.KeyPress += new KeyPressEventHandler((sender, args) =>
     {
         if (args.KeyChar == 13)
         {
             tbConfirm.Focus();
         }
     });
 }