增加SharePoint2010修改域密码功能
转:http://blog.163.com/hr_test/blog/static/16485210720137953131694/
前提
SharePoint2010的用户基于AD的,因此修改密码是修改了AD的密码,当然也可以修改本机密码(非域的密码)。这里我们讨论修改域密码。我们修改需要用到sharepoint的弹出对话框的模式,以下为几个对话框函数:
? SP.UI.ModalDialog.showModalDialog:弹出对话框
? SP.UI.Status.addStstus:自定义状态栏信息
? SP.UI.Notify.addNotification:自定义消息通知
配置开发
1. 使用sharepoint designer2010打开对应站点http://moss:8002 ,找到v4.master如下图:
2. 打开编辑v4.master,如下图:
添加JS代码:
采用自定义通知栏模式<script language="javascript" type="text/javascript">function portal_openModalDialog(){var options = SP.UI.$create_DialogOptions();options.width = 500;options.height = 250;options.url = "/_layouts/TCL.EG.ModifyPasswd/ModifyPasswd.aspx";options.dialogReturnValueCallback = Function.createDelegate(null, portal_modalDialogClosedCallback);SP.UI.ModalDialog.showModalDialog(options);}//关闭函数function portal_modalDialogClosedCallback(result, value){if (value == "1"){//自定义通知栏SP.UI.Notify.addNotification("恭喜!修改成功!");}else if (value == "0"){//自定义通知栏SP.UI.Notify.addNotification("修改失败,请联系管理员!");}}//关闭函数function closeDialog(){SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 3);}</script>?采用自定义状态栏模式
<script language="javascript" type="text/javascript">function portal_openModalDialog(){var options = SP.UI.$create_DialogOptions();options.width = 500;options.height = 250;options.url = "/_layouts/TCL.EG.ModifyPasswd/ModifyPasswd.aspx";options.dialogReturnValueCallback = Function.createDelegate(null, portal_modalDialogClosedCallback);SP.UI.ModalDialog.showModalDialog(options);}//关闭函数function portal_modalDialogClosedCallback(result, value){if (value == "1"){//自定义状态栏this.statusId = SP.UI.Status.addStatus ("恭喜!修改成功!",“修改密码成功,请重新登录!”,true);}else if (value == "0"){//自定义通知栏this.statusId =SP.UI.Status.addStatus ("修改失败!",“修改失败,请联系管理员!”,true);}SP.UI.Status.setStatusPriColor(this.statusId, "Green");setTimeout(RemoveStatus, 6000);}function RemoveStatus() {SP.UI.Status.removeStatus(this.statusId);}//关闭函数function closeDialog(){SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel, 3);}</script>
加入母版页面中,签入即可,如下图:
3. 使用VS2010开发添加sharepoint空白项目,如下图:
4. 添加空元素,如下图:
<?xml version="1.0" encoding="utf-8"?><Elements xmlns="http://schemas.microsoft.com/sharepoint/"><CustomActionId="{BC477D9E-365A-47BD-AB2B-BE06FA44628D}"Title="修改密码"Description="此处修改的是域里面的密码"Sequence="1000"Location="Microsoft.SharePoint.StandardMenu"GroupId="PersonalActions"ImageUrl="~sitecollection/_layouts/images/menulistsettings.gif"><UrlAction Url="javascript:portal_openModalDialog();"/></CustomAction></Elements>
5. 添加修改密码的页面,页面代码部分如下:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %><%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %><%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %><%@ Import Namespace="Microsoft.SharePoint" %><%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %><%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ModifyPasswd.aspx.cs" Inherits="TCL.EG.ModifyPasswd.Layouts.TCL.EG.ModifyPasswd.ModifyPasswd"DynamicMasterPageFile="~masterurl/default.master" %><asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server"></asp:Content><asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server"><table cellpadding="0" cellspacing="0" border="0"><tr><td>旧密码:</td><td><asp:TextBox ID="txtOldPwd" runat="server" TextMode="Password"></asp:TextBox></td></tr><tr><td>新密码:</td><td><asp:TextBox ID="txtNewPwd" runat="server" TextMode="Password"></asp:TextBox></td></tr><tr><td>确认密码:</td><td><asp:TextBox ID="txtConfirmPwd" runat="server" TextMode="Password"></asp:TextBox></td></tr><tr><td><asp:Button ID="btnUpdate" runat="server" Text="保存" OnClick="btnUpdate_Click" /></td><td><asp:Button ID="btnCancel" runat="server" Text="取消" OnClientClick="closeDialog()" /></td></tr><tr><td colspan="2"><font color="red"><asp:Label ID="Label_Title" runat="server" ></asp:Label></font></td></tr></table></asp:Content><asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">修改密码</asp:Content><asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"runat="server">我的应用程序页</asp:Content>
6、后台代码.cs部分,如下:
using System;using Microsoft.SharePoint;using Microsoft.SharePoint.WebControls;using System.DirectoryServices.AccountManagement;using System.Security.Principal;using System.Runtime.InteropServices;using System.ComponentModel;using System.DirectoryServices;namespace TCL.EG.ModifyPasswd.Layouts.TCL.EG.ModifyPasswd{public partial class ModifyPasswd : LayoutsPageBase{#region//变量/// <summary>////// </summary>private string _userName;////// </summary>private PrincipalContext _principalContext;private string newPasswd = string.Empty;private string confirmPasswd = string.Empty;private string oldPasswd = string.Empty;#endregion#region//事件protected void Page_Load(object sender, EventArgs e){if (!Page.IsPostBack){}}/// <summary>/// 更新密码/// </summary>/// <param name="sender"></param>/// <param name="e"></param>protected void btnUpdate_Click(object sender, EventArgs e){if (SPContext.Current != null){//登录名_userName = SPContext.Current.Web.CurrentUser.LoginName;//if (_userName.ToLower() == "sharepoint\\system"){_userName = "contoso\\mossadmin";}//旧密码不允许为空//修改密码newPasswd = this.txtNewPwd.Text.Trim();confirmPasswd = this.txtConfirmPwd.Text.Trim();oldPasswd = txtOldPwd.Text.Trim();//if (string.IsNullOrEmpty(oldPasswd)){this.Label_Title.Text = "请输入旧密码!";return;}if (string.IsNullOrEmpty(newPasswd)){this.Label_Title.Text = "请输入新密码!";return;}if (string.IsNullOrEmpty(confirmPasswd)){this.Label_Title.Text = "请输入确认密码!";return;}//判断2次密码是否一致。if (newPasswd != confirmPasswd){this.Label_Title.Text = "新密码与确认密码不一致!";return;}//_userNameif (!string.IsNullOrEmpty(_userName)){//登录名为contoso\\mossadmintry{//检查原始密码是否正确bool isOK = CheckUser(ValidType.Domain, _userName, oldPasswd);//如果正确if (!isOK){this.Label_Title.Text = "旧密码输入错误!";return;}else{//更改密码bool isreult = UpdateMyPassword(newPasswd, oldPasswd);//if (isreult){//提示信息Response.Write("<script type=\"text/javascript\">window.frameElement.commonModalDialogClose(1, 1);</script>");}}}catch (Exception ex){this.Label_Title.Text = ex.Message;}}}}#endregion#region//方法#region//修改密码/// <summary>/// 修改密码/// </summary>/// <param name="newUserPasswd">新密码</param>/// <param name="oldUserPasswd">原始密码</param>/// <returns>返回结果是否成功</returns>private bool UpdateMyPassword(string newUserPasswd,string oldUserPasswd){//返回okbool _result = false;try{Impersonator Imp = new Impersonator();//开始Imp.BeginImpersonation();//using (var context = new PrincipalContext(ContextType.Domain)){using (UserPrincipal usr = UserPrincipal.FindByIdentity(context,IdentityType.SamAccountName,Microsoft.SharePoint.SPContext.Current.Web.CurrentUser.LoginName)){usr.UserCannotChangePassword = true;usr.ChangePassword(oldUserPasswd, newUserPasswd);}}//修改if (Imp.IsImpersonated){Imp.StopImpersonation();//Ok_result = true;}else{//fail_result = false;}}catch(Exception ex){this.Label_Title.Text = ex.Message;_result = false;}//returnreturn _result;}#endregion#region//验证原始密码是否正确/// <summary>/// 验证原始密码是否正确/// </summary>/// <param name="validType">验证类型</param>/// <param name="UserName">登录名</param>/// <param name="PassWord">登录密码</param>/// <returns>返回是否成功的标识</returns>public Boolean CheckUser(ValidType validType, String UserName, String PassWord){try{String[] UserArray = UserName.Split(new char[] { '\\' }); //UserName 組合為 Domain\Account 或 MachineName\AccountInitPC(validType, UserArray[0]);Boolean isValid = _principalContext.ValidateCredentials(UserArray[1], PassWord);return isValid;}catch (Exception ex){this.Label_Title.Text = ex.Message;return false;}}#endregion#region//PrincipalContext初始化/// <summary>/// PrincipalContext初始化/// </summary>/// <param name="validType">验证类型</param>/// <param name="LDAPName">应用程序</param>private void InitPC(ValidType validType, String LDAPName){//PrincipalContext pc = null;int typeNum = (int)validType;switch (typeNum){case 1:_principalContext = new PrincipalContext(ContextType.Domain, LDAPName);break;case 2:_principalContext = new PrincipalContext(ContextType.Machine, LDAPName);break;case 3:_principalContext = new PrincipalContext(ContextType.ApplicationDirectory, LDAPName);break;default:break;}}#endregion#region//枚举类型/// <summary>/// 枚举类型/// </summary>public enum ValidType{/// <summary>/// 域/// </summary>Domain = 1,/// <summary>/// 机器/// </summary>Machine = 2,/// <summary>/// 应用程序/// </summary>ApplicationDirectory = 3}#endregion#endregion}}
7. Impersonator.cs代码部分如下:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Security.Principal;namespace TCL.EG.ModifyPasswd{public class Impersonator{private WindowsImpersonationContext ctx = null;public bool IsImpersonated { get; set; }public void BeginImpersonation(){try{if (!WindowsIdentity.GetCurrent().IsSystem){ctx = WindowsIdentity.Impersonate(WindowsIdentity.GetCurrent().Token);IsImpersonated = true;}}catch{IsImpersonated = false;}}public void StopImpersonation(){if (ctx != null){ctx.Undo();}}}}
8. 部署后,看下效果图:
自定义通知栏效果图:
自定义状态栏效果图:
注意事项:
1、 密码复杂度策略,最好合符要求,否则会提示:密码不合符复杂度策略。要不,干脆不禁用此策略,在代码中用自己定义策略,用正则表达式,如下图:
2、 为了能每天多次修改密码,此时应当禁用如下策略,如下图:
否则定义好,必须按照此策略进行。策略更新后请重启系统或用gpupdate进行策略刷新即可。
增加SharePoint2010修改域密码功能的更多相关文章
- 为VisualSVN Server增加在线修改用户密码的功能
原文:为VisualSVN Server增加在线修改用户密码的功能 附件下载:点击下载 VisualSVN Server是一个非常不错的SVN Server程序,方便,直观,用户管理也异常方便. 不过 ...
- Microsoft Dynamics CRM 如何修改域密码
一.安装IIS6脚本工具,如下图所示: 二.复制iisadmpwd文件夹到AD Server的C:\Windows\SysWOW64\inetsrv文件夹下 三.注册Iisadmpwd目录下的IISp ...
- 基于SpringBoot从零构建博客网站 - 设计可扩展上传模块和开发修改头像密码功能
上传模块在web开发中是很常见的功能也是很重要的功能,在web应用中需要上传的可以是图片.pdf.压缩包等其它类型的文件,同时对于图片可能需要回显,对于其它文件要能够支持下载等.在守望博客系统中对于上 ...
- Sharepoint增加修改密码功能
Sharepoint中没有自带的修改密码的功能. 如果使用的是AD验证,修改密码,只要修改域帐号的用户名密码就可以了.以下代码可以修改本机密码和域帐号密码. 做法是,添加一个webpart,做一个页面 ...
- SharePoint2013 以其他用户登录和修改AD域用户密码 功能
sharepoint默认是没有修改AD密码 和切换 用户的功能,这里我用future的方式来实现. 部署wsp前: 部署后: 点击以其他用户身份登录 点击修改用户密码: 这里的扩展才菜单我们用Cust ...
- Window通过Web方式修改域用户密码
如何通过web方式修改域用户密码: 1.在Windows Server 2003上,系统默认提供了iisadmpwd作为一种修改域用户密码的方式 2.在Windows Server 2008上,可以提 ...
- python3之对本地TXT文件进行增加,删除,修改,查看功能。
由于是初学,代码如有不足,欢迎指出! 本博客记录我的编程之路,记录所学到的知识,分享所学心得! 这是我的一个作业. 首先分析要求: 创建一个TXT文件用于存储账号与密码 实现对文件进行增加,删除,修改 ...
- windows server 2008 修改域的密码策略
1.一般情况下,进入本地安全策略修改密码策略时,,密码策略已经被锁定,无法更改,若要修改域服务器上的密码策略,请按照步骤2--6进行修改 2.在此情况下要改密码策略的过程如下, 进入组策略管理: 3. ...
- javaWeb实现使用邮箱邮件找回密码功能
JSP+Jmail+JavaBean 发邮件(转)2010-08-23 18:052007年04月14日 14:32/* * SendMail.java * * Created on 2007年3月3 ...
随机推荐
- JS 变量或参数是否有值的判断
var node; …… 判断 node 是否有值,是否为 undefine,是否 null,直接使用两个!!,否定之否定: if (!!node){ .... }else{ .... } 这个条件判 ...
- 套题T2
数学(math.cpp) DXY的数学很差... 对于所有1<=i<=N求(2^i – i^2)能被7整除的个数.(N<=1000000) 样例输入: 3 样例输出: 1 你在代码中 ...
- 区间dp笔记√
区间DP是一类在区间上进行dp的最优问题,一般是根据问题设出一个表示状态的dp,可以是二维的也可以是三维的,一般情况下为二维. 然后将问题划分成两个子问题,也就是一段区间分成左右两个区间,然后将左右两 ...
- Sina App Engine(SAE)入门教程(4)- SaeVCode(验证码服务)使用
参考资料 SaeVCode api 文档 使用教程 所有的验证码原理都是生成一个vcode字符串,存到session中,和用户的输入进行比较判断,以下是一个使用验证码服务的完整实例: 首页index. ...
- Windows下Subversion和Apache的安装及配置(一)
1.序 Subversion可谓版本控制软件中的佼佼者,其开源性,易用性已受到众多软件开发者首选的版本控制软件.在这里我想记录我安装Subversion和Apache的过程.注意,Subversion ...
- 用ISO C++实现自己的信号槽(Qt另类学习)
qtc++objectsignalclassstring 目录(?)[-] Qt信号与槽 引入元对象系统 建立信号槽链接 信号的激活 槽的调用 全家福 零零散散写在后面 Q_OBJECT Conn ...
- [iOS]解决模拟器无法输入中文问题
第一步:设置schem 菜单项 -> Product-> Scheme -> Edit Scheme -> 然后在弹出的界面里 选择OPtion 项, 设置 Applicat ...
- *IDEA真好用
使用maven做开发,在编辑pom.xml文件时
- js学习对象创建
Object.extend = function(destination, source) {for (var property in source) { destination[propert ...
- iOSTab bar
http://www.apkbus.com/android-130504-1-1.html #import #import "FirstViewController.h"#impo ...