コード例 #1
0
        public void ModifyPassword(string userName, string oldPassword, string newPassword)
        {
            if (string.IsNullOrWhiteSpace(userName))
            {
                throw new Exception("用户名非法。");
            }

            // 新密码是否合法?

            // 旧密码是否正确?
            var theUser = this.GetUser(userName);

            if (theUser == null)
            {
                throw new Exception("用户不存在。");
            }

            var oldPwdMd5 = HelperTool.BuildMd5(oldPassword);

            if (!HelperTool.BytesEquals(oldPwdMd5, theUser.Password))
            {
                throw new Exception("旧密码不正确。");
            }

            // 更新密码。
            var newPwdMd5 = HelperTool.BuildMd5(newPassword);

            GlobalServices.Repository.Update <User>(new { Password = newPwdMd5 }, p => p.Code == theUser.Code);
        }
コード例 #2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                var actualPwd = HelperTool.BuildMd5(txtPassword.Text);
                this.Verification.LogOn(txtUserName.Text, actualPwd);

                this.Close();

                _retryTimes = 0;

                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                if (++_retryTimes > 2)
                {
                    this.DialogResult = DialogResult.No;
                }
                MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }