public bool SignInCheck(string strLogonName, string strUserPwd) { bool result = false; if (strLogonName.IsNotEmpty()) { string key = strLogonName + strUserPwd; SchemaObjectBase userObj = SchemaObjectAdapter.Instance.LoadByCodeName(StandardObjectSchemaType.Users.ToString(), strLogonName, SchemaObjectStatus.Normal, DateTime.MinValue); ExceptionHelper.FalseThrow <ApplicationException>(userObj != null, "用户\"{0}\"不存在", strLogonName); result = UserPasswordAdapter.Instance.CheckPassword(userObj.ID, UserPasswordAdapter.GetPasswordType(), strUserPwd); (userObj.CurrentParentRelations.Count > 0).FalseThrow("账户\"{0}\"必须属于一个组织", strLogonName); if (userObj.Properties.GetValue("PasswordNotRequired", false) == false) { result = UserPasswordAdapter.Instance.CheckPassword(userObj.ID, UserPasswordAdapter.GetPasswordType(), strUserPwd); } else { result = true; } if (result) { userObj.Properties.GetValue("AccountDisabled", false).TrueThrow("账户\"{0}\"已经被禁用", strLogonName); (userObj.Properties.GetValue("AccountExpires", DateTime.MaxValue) > DateTime.Now || userObj.Properties.GetValue("AccountExpires", DateTime.MaxValue) == DateTime.MinValue).FalseThrow("账户\"{0}\"已过期", strLogonName); (userObj.Properties.GetValue("AccountInspires", DateTime.MinValue) < DateTime.Now).FalseThrow("账户\"{0}\"还没有到启用时间", strLogonName); } } return(result); }
protected void OK_Click(object sender, EventArgs e) { if (this.Page.IsValid) { TimePointContext context = TimePointContext.GetCurrentState(); try { TimePointContext.Current.SimulatedTime = DateTime.MinValue; TimePointContext.Current.UseCurrentTime = true; var user = PC.Adapters.SchemaObjectAdapter.Instance.LoadByCodeName(StandardObjectSchemaType.Users.ToString(), this.txtLogOnName.Text, SchemaObjectStatus.Normal, DateTime.MinValue); if (user != null) { if (user.CurrentParentRelations.Exists(p => p.Status == SchemaObjectStatus.Normal && p.ParentSchemaType == "Organizations" && p.Parent.Status == SchemaObjectStatus.Normal) == false) { throw new InvalidOperationException(string.Format("没有找到对应登录名 {0} 的用户的组织,必须先将用户加入组织。", this.txtLogOnName.Text)); } var userId = user.ID; bool valid = false; if (this.SupervisiorMode) { if (this.txtLogOnName.Text == Util.CurrentUser.LogOnName) { // 管理员修改自己的 if (UserPasswordAdapter.Instance.CheckPassword(userId, UserPasswordAdapter.GetPasswordType(), this.tb_OldPassword.Value) == true) { valid = true; } else { this.passwordresult.InnerText = "原始密码不正确"; } } else { // 修改别人的,检查管理员的密码是否正确 if (UserPasswordAdapter.Instance.CheckPassword(Util.CurrentUser.ID, UserPasswordAdapter.GetPasswordType(), this.tb_OldPassword.Value) == true) { valid = true; } else { this.passwordresult.InnerText = "管理员密码错误"; } } } else { if (UserPasswordAdapter.Instance.CheckPassword(userId, UserPasswordAdapter.GetPasswordType(), this.tb_OldPassword.Value) == true) { valid = true; } else { this.passwordresult.InnerText = "原始密码不正确"; } } if (valid) { UserPasswordAdapter.Instance.SetPassword(userId, UserPasswordAdapter.GetPasswordType(), this.tb_NewPassword.Value); ScriptManager.RegisterClientScriptBlock(this.passwordUpdatePanel, this.GetType(), "master", "top.window.close();", true); } } else { throw new ObjectNotFoundException(string.Format("未能找到对应登录名 {0} 的用户。", this.txtLogOnName.Text)); } } catch (Exception ex) { this.passwordresult.InnerText = string.Format("无法验证用户,{0}", ex.Message); // WebUtility.RegisterClientErrorMessage(ex); // ScriptManager.RegisterStartupScript(this.passwordUpdatePanel, this.GetType(), "提示", "window.alert('原密码不正确')", true); } finally { TimePointContext.RestoreCurrentState(context); } } }