Asp.Net模拟域验证登录及密码修改
来源:互联网 发布:微信浏览器js跳转页面 编辑:程序博客网 时间:2024/05/22 13:14
示例代码为Asp.Net MVC程序,仅供参考!
需要引用命名空间:
using System.DirectoryServices;
Login.cshtml代码:
@{ ViewBag.Title = "模拟域验证"; Layout = "~/Views/Shared/_Layout.cshtml";}<h2>模拟域验证</h2>@using (Html.BeginForm()) { <p>用户名:@Html.TextBox("UserName")</p> <p>旧密码:@Html.Password("OldPassword")</p> <p>新密码:@Html.Password("NewPassword")</p> <p><input type="submit" value="登录" /></p>}@ViewData["Msg"]
cs代码:
[AcceptVerbs(HttpVerbs.Post)][ValidateInput(false)]public ActionResult Login(string UserName, string OldPassWord, string NewPassWord){ DirectoryEntry AD = new DirectoryEntry(); AD.Path = string.Format("LDAP://{0}", IPAddress); AD.Username = "domain" + @"\" + UserName; AD.Password = OldPassWord; AD.AuthenticationType = AuthenticationTypes.Secure; try { DirectorySearcher searcher = new DirectorySearcher(AD); searcher.Filter = String.Format("(&(objectClass=user)(samAccountName={0}))", UserName); System.DirectoryServices.SearchResult result = searcher.FindOne(); if (result != null) { DirectoryEntry userEntry = result.GetDirectoryEntry(); if (userEntry != null) { try { userEntry.Invoke("ChangePassword", new Object[] { OldPassWord, NewPassWord }); userEntry.CommitChanges(); userEntry.Close(); ViewData["Msg"] = "修改密码成功!"; } catch (Exception ex) { ViewData["Msg"] = "操作失败,错误原因:" + ex.ToString(); } } } else { ViewData["Msg"] = "操作失败,未知账号或密码错误!"; } AD.Close(); } catch (Exception ex) { ViewData["Msg"] = "操作失败,错误原因:" + ex.ToString(); } return View();}
0 0
- Asp.Net模拟域验证登录及密码修改
- Asp.Net 中验证 Discuz 的登录密码
- ASP.NET面向角色授权之:自带登录控件登录验证与授权原理及自定义修改方法。
- ASP.NET 登录验证
- asp.net 邮箱验证 密码
- ASP.net 登录验证码
- ASP.NET登录验证代码
- asp.net登录票据验证
- ASP.NET登录验证码
- C#密码修改及验证
- asp.net 服务器端的验证控件——密码修改验证
- ASP.NET 修改密码代码
- asp.net系统增加用户登录后修改密码的功能
- asp.net登录界面记住密码
- ASP.NET密码强度的验证
- 生成登录验证码(asp.net)
- asp.net的登录验证方法
- [Asp.Net MVC4]验证用户登录实现
- 编译报警告 Warning: Multiple build commands for output file
- 懒加载异常的解决办法
- hibernate注解 之 时间
- ch4.6: find the LCA of 2 nodes in a binary tree with 3 different methods
- 谜题1:奇数性
- Asp.Net模拟域验证登录及密码修改
- 用C#对Active Directory进行增删修查的类源码
- 自动装箱和自动拆箱
- javaWEB项目性能调优
- poj3348
- 位域的操作
- Step By Step Mini Site Video Training
- HDU 2973 / UVa 1434 / CERC 2008 YAPTCHA (威尔逊定理及其逆定理)
- Android中如何使用WIFI来连接ADB