亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? authentication.cs

?? JAVA實現的RSA公鑰加密方法
?? CS
字號:
using System;
using System.DirectoryServices;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.Specialized;
using Microsoft.VisualBasic;
using System.Security.Principal;
using System.Threading;

namespace DJD.Security
{

	/// <summary>
	/// Integrates with ActiveDirectory Servers for purpose of authentication. Developed by Dom DiNatale 11/15/02
	/// </summary>
	[Guid("4AC6FEAF-42EC-4c35-A21E-DE3820171626"), ClassInterface(ClassInterfaceType.AutoDual)]
	public class Authentication : IDisposable
	{
		[DllImport("advapi32.dll", SetLastError=true)]
		private static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, 
			int dwLogonType, int dwLogonProvider, ref IntPtr phToken);

		[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
		private extern static bool CloseHandle(IntPtr handle);

		[DllImport("advapi32.dll", CharSet=CharSet.Auto, SetLastError=true)]
		private extern static bool DuplicateToken(IntPtr ExistingTokenHandle, 
			int SECURITY_IMPERSONATION_LEVEL, ref IntPtr DuplicateTokenHandle);



		#region Enums
		public enum AuthenticationTypes
		{
			ActiveDirectory,
			LDAP
		}
		#endregion

		#region Declarations
		private string _path = "";
		private System.Collections.SortedList _usrPropsDict;
		private AuthenticationTypes _authtype = AuthenticationTypes.ActiveDirectory;
		#endregion

		#region Properties
		/// <summary>
		/// Provides every domain name available on the network.
		/// </summary>
		public System.Collections.SortedList Domains
		{
			get
			{
				return GetDomains();
			}

		}
		public AuthenticationTypes AuthType
		{
			get
			{
				return _authtype;
			}
			set
			{
				_authtype = value;
			}

		}

		/// <summary>
		/// Provides every domain name available on the network.
		/// </summary>
		public string[] DomainsStr
		{
			
			get
			{
				SortedList sl = GetDomains();
				string[] m_array = new string [sl.Count];
				
				for (int i = 0; i <= sl.Count-1; i++)
				{
					m_array[i] = sl.GetKey(i).ToString();
				}
				return m_array;
			}

		}
		/// <summary>
		/// Provides the ActiveDirectory path currently being used.
		/// </summary>
		public string Path
		{
			get
			{
				return _path;
			}
		}

		/// <summary>
		/// Provides all of the properties for the current user in a ListDictionary format.
		/// </summary>
		public System.Collections.SortedList Properties
		{
			get
			{
				return _usrPropsDict;
			}

		}

		#endregion

		#region Public Methods
		/// <summary>
		/// Starts a new instance of this class.
		/// </summary>
		public Authentication()
		{
		}
	
		/// <summary>
		/// Authenticates a user in the specified domain against ActiveDirectory Server(s).
		/// </summary>
		/// <param name="domain">The domain the account is to be authenticated in.</param>
		/// <param name="UserID">The Windows NT UserID.</param>
		/// <param name="password">The password for the UserID.</param>
		/// <returns>Returns a string: "True" if successful, or exception message if unsuccessful.</returns>
		public string Authenticate(string domain, string userID, string password)
		{
			string domainAndUsername = domain + "\\" + userID;
			string retVal;
			switch (_authtype)
			{
				case Authentication.AuthenticationTypes.ActiveDirectory:
					_path = "WinNT://" + domain;
					break;
				case Authentication.AuthenticationTypes.LDAP:
					_path = "LDAP://" + domain;
					break;
			}
			DirectoryEntry entry;
			try
			{	
				entry = new DirectoryEntry(_path, domainAndUsername, password, System.DirectoryServices.AuthenticationTypes.ReadonlyServer);
						
				object obj = entry.NativeObject; /// makes sure the object is bound.
				_path = entry.Path;
				retVal = "True";
				obj = null;
				entry.Close();
				entry.Dispose();
				entry = null;
				GC.Collect();

				//Resolve(domain,userID,domain,userID,password);
			}
			catch(Exception ex)
			{
				retVal = ex.Message;
			}
			finally
			{
				
				GC.Collect();
			}
			return retVal;
		}

		/// <summary>
		/// Allows you to change the password of a user.
		/// </summary>
		/// <param name="domain">The domain the use is in.</param>
		/// <param name="userID">The users' id</param>
		/// <param name="oldPassword">The current password.</param>
		/// <param name="newPassword">The new password.</param>
		/// <returns>True if successful, False if not.</returns>
		public bool ChangePassword(string domain, string userID, string oldPassword, string newPassword)
		{
			string result = "";
			return ChangePassword(domain,userID,oldPassword,newPassword,ref result);
		}
		
		/// <summary>
		/// Allows you to change the password of a user.
		/// </summary>
		/// <param name="domain">The domain the use is in.</param>
		/// <param name="userID">The users' id</param>
		/// <param name="oldPassword">The current password.</param>
		/// <param name="newPassword">The new password.</param>
		/// <param name="result">error message if there is one</param>
		/// <returns>True if successful, False if not.</returns>
		public bool ChangePassword(string domain, string userID, string oldPassword, string newPassword, ref string result)
		{
			// *** IMPORTANT INFORMATION *** //
			// When you call a function like this, the credentials from the earliest caller are used to contact Active
			// Directory. For example. If you were to use this in a web application, the application serving the web server 
			// would have to be running under an account that has access to AD. (Win2K: inetinfo.exe, Win2K3 (IIS6): w3wp.exe)
			// In IIS 6, you can set this at the application pool level. Note that the user you provide needs the same
			// access as the NETWORK SERVICE account (check local and group policies). 
			// There is an attempted workaround for this restriction in the catch statement below (commented out). 
			// This approach will not work in a web application, you'll get an error about not being able to impersonate.
			// It may work, however in a win application. 

			string domainAndUsername = domain + "\\" + userID;
			switch (_authtype)
			{
				case Authentication.AuthenticationTypes.ActiveDirectory:
					_path = "WinNT://" + domain;
					break;
				case Authentication.AuthenticationTypes.LDAP:
					_path = "LDAP://" + domain;
					break;
			}
			try
			{	
				DirectoryEntry ent = new DirectoryEntry();
				ent.Username = domain + "/" + domain + "\\" + userID;
				ent.Password = oldPassword;
				ent.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Secure;
			
				object obj1 = ent.NativeObject; /// makes sure the object is bound.
				
				DirectorySearcher Searcher = new DirectorySearcher(ent,"(sAMAccountName=" + userID + ")");
				Searcher.SearchScope = SearchScope.Subtree;
				SearchResult sResult = Searcher.FindOne();

				_path = sResult.GetDirectoryEntry().Path;
				
				ent = sResult.GetDirectoryEntry();
				ent.Invoke("ChangePassword", new object[] {oldPassword, newPassword});
				ent.CommitChanges();
				return true;		
			}
			catch(Exception ex)
			{
				// This hasn't been tested very well, so use it at your own risk... it should work though!
				//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemsecurityprincipalwindowsidentityclassimpersonatetopic2.asp
//////				try //attempt to impersonate the user that is trying to logon rather than using the 
//////					// credentials of the person calling this function.
//////				{
//////					const int LOGON32_PROVIDER_DEFAULT = 0;
//////					const int LOGON32_LOGON_INTERACTIVE = 2;					//This parameter causes LogonUser to create a primary token.
//////					const int SecurityImpersonation = 2;
//////
//////					Console.WriteLine("Before impersonation: " + WindowsIdentity.GetCurrent().Name);
//////
//////					IntPtr tokenHandle = new IntPtr(0);
//////					IntPtr dupeTokenHandle = new IntPtr(0);
//////					//try to logon the user
//////					bool returnValue = LogonUser(userID,domain,oldPassword,LOGON32_LOGON_INTERACTIVE,LOGON32_PROVIDER_DEFAULT, ref tokenHandle);
//////					if (returnValue == true) 
//////					{
//////						bool retVal = DuplicateToken(tokenHandle, SecurityImpersonation, ref dupeTokenHandle);
//////						if (retVal)
//////						{
//////							WindowsIdentity newId = new WindowsIdentity(dupeTokenHandle);
//////							WindowsImpersonationContext impersonatedUser = newId.Impersonate();
//////							Console.WriteLine("After impersonation: " + WindowsIdentity.GetCurrent().Name);
//////
//////							// COPIED FROM ABOVE TO CHANGE PASSWORD
//////							DirectoryEntry ent = new DirectoryEntry();
//////							ent.Username = domain + "/" + domain + "\\" + userID;
//////							ent.Password = oldPassword;
//////							ent.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Secure;
//////			
//////							object obj1 = ent.NativeObject; /// makes sure the object is bound.
//////				
//////							DirectorySearcher Searcher = new DirectorySearcher(ent,"(sAMAccountName=" + userID + ")");
//////							Searcher.SearchScope = SearchScope.Subtree;
//////							SearchResult sResult = Searcher.FindOne();
//////
//////							_path = sResult.GetDirectoryEntry().Path;
//////				
//////							ent = sResult.GetDirectoryEntry();
//////							ent.Invoke("ChangePassword", new object[] {oldPassword, newPassword});
//////							ent.CommitChanges();
//////							// END COPY
//////
//////							return true;
//////						}
//////						else
//////						{
//////							CloseHandle(tokenHandle);
//////							Console.WriteLine("Exception thrown in trying to duplicate token.");        
//////						}
//////					}
//////				}
//////				catch (Exception ex1)
//////				{
//////					Console.WriteLine (ex1.Message);
//////				}

				result = ex.Message;
				return false;
			}		
		}

		/// <summary>
		/// Returns the FullName property of a given UserID in a give Domain on the network. Also fills the Path and Properties properties with data. In order to access ActiveDirectory or LDAP, the function will use the credentials of the process calling it. Otherwise call the overloaded function with LDAP credentials.
		/// </summary>
		/// <param name="domain">the domain to be resolved in</param>
		/// <param name="UserID">the user id</param>
		/// <returns></returns>
		public string Resolve(string domain, string userID)
		{
			return Resolve(domain, userID, null, null, null);
		}
		

		/// <summary>
		/// Returns the FullName property of a given UserID in a give Domain on the network. Also fills the Path and Properties properties with data.
		/// </summary>
		/// <param name="domain">the domain to be resolved in</param>
		/// <param name="UserID">the user id</param>
		/// <returns></returns>
		public string Resolve(string domain, string UserID, string guestDomain, string guestUserID, string guestPassword)
		{
			string retVal;
			
			switch (_authtype)
			{
				case Authentication.AuthenticationTypes.ActiveDirectory:
					_path = "WinNT://" + domain;
					break;
				case Authentication.AuthenticationTypes.LDAP:
					_path = "LDAP://" + domain;
					break;
			}

//New CODE:
			DirectoryEntry ent = new DirectoryEntry();
			ent.Path = _path;
			if ((guestDomain != null) || (guestUserID != null) || (guestPassword != null))
			{
				ent.Username = guestDomain + "/" + guestDomain + "\\" + guestUserID;
				ent.Password = guestPassword;
			}

			ent.AuthenticationType = System.DirectoryServices.AuthenticationTypes.Secure;
			
			object obj1 = ent.NativeObject; /// makes sure the object is bound.

            DirectorySearcher Searcher = new DirectorySearcher(ent,"(sAMAccountName=" + UserID + ")");
			Searcher.SearchScope = SearchScope.Subtree;
			SearchResult result = Searcher.FindOne();

			System.DirectoryServices.PropertyCollection pc = result.GetDirectoryEntry().Properties;
			_path = result.GetDirectoryEntry().Path;
			
			_usrPropsDict = new System.Collections.SortedList();
			
			foreach(string name in pc.PropertyNames)
			{				
				_usrPropsDict.Add(name,pc[name][0]); //assign the value
				//http://www.microsoft.com/technet/scriptcenter/topics/win2003/lastlogon.mspx
				object o = pc[name][0]; //determine if the value is of type IADsLargeInteger
				if ((o as Interop.ActiveDS.IADsLargeInteger)!=null)
				{
					//Console.WriteLine (name + " is a IADSLargeInteger!");
					Interop.ActiveDS.IADsLargeInteger val = (Interop.ActiveDS.IADsLargeInteger)o;
					try
					{
						double dblDateTime = 0;
						DateTime newTime = new DateTime(1601,1,1);
						dblDateTime = (val.HighPart * (System.Math.Pow(2,32)));
						dblDateTime += val.LowPart;
						dblDateTime = dblDateTime / (60 * 10000000);
						dblDateTime = dblDateTime / 1440;
						//Console.WriteLine(dblDateTime);
						//Console.WriteLine (name + ": " + newTime.AddDays(dblDateTime));
						_usrPropsDict[name] = newTime;
					}
					catch (ArgumentOutOfRangeException ex) //i.e. - Account Expires = never.
					{
						Console.WriteLine(ex.ToString());
						_usrPropsDict[name] = false;
					}
					//Console.WriteLine(); 
				}
				
			}

			retVal = _usrPropsDict["displayName"].ToString();
			retVal = retVal.Trim();
		
			ent.Close();
			GC.Collect();
			return retVal;
		}

		public void Dispose()
		{
			Dispose(true);
			GC.SuppressFinalize(this);
			
		}

		
		#endregion

		#region Private Methods
private void Dispose(bool disposing)
	{
		if (disposing)
		{
			_usrPropsDict = null;
		}
		else
		{
		}
	}
private void Finalize()
	{
		Dispose(false);
	}
						
private System.Collections.SortedList GetDomains()
		{
			System.Collections.SortedList alTemp = new System.Collections.SortedList();
		
			switch (_authtype)
			{
				case Authentication.AuthenticationTypes.ActiveDirectory:
					_path = "WinNT:";
					break;
				case Authentication.AuthenticationTypes.LDAP:
					_path = "LDAP:";
					break;
			}
			DirectoryEntry entry = new DirectoryEntry(_path);
			foreach(DirectoryEntry d in entry.Children)
			{
				alTemp.Add(d.Name,d.Name);
			}
			entry.Close();
			GC.Collect();
			return alTemp;
		}
	
		#endregion
	
	}

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人综合婷婷国产精品久久| 久久久久九九视频| 久久综合狠狠综合久久激情 | 亚洲美女视频在线观看| 久久99精品一区二区三区| 欧美性做爰猛烈叫床潮| 国产女人18毛片水真多成人如厕| 午夜精品久久久久久久99水蜜桃 | 丰满放荡岳乱妇91ww| 欧美一区二区在线免费观看| 亚洲欧美日本韩国| 国产美女在线精品| 日韩精品一区二| 日韩一区欧美二区| 欧美日韩国产经典色站一区二区三区| 亚洲欧美日韩国产手机在线| 成人免费看黄yyy456| 久久精品欧美日韩| 国产在线播放一区三区四| 日韩欧美国产综合| 免费成人av资源网| 日韩欧美亚洲一区二区| 免费在线看一区| 欧美一区二区三区在线观看视频| 亚洲国产精品视频| 欧美丝袜丝交足nylons| 亚洲亚洲精品在线观看| 欧美日韩精品系列| 婷婷亚洲久悠悠色悠在线播放| 欧美综合亚洲图片综合区| 亚洲伦理在线精品| 欧美性一级生活| 亚洲国产日韩av| 欧美精品 日韩| 免费观看30秒视频久久| 欧美成人乱码一区二区三区| 黄色成人免费在线| 日本一区二区视频在线观看| 粗大黑人巨茎大战欧美成人| 国产精品美女视频| 91福利视频网站| 香蕉久久一区二区不卡无毒影院| 欧美日本韩国一区| 成人在线一区二区三区| 国产成人欧美日韩在线电影| 51久久夜色精品国产麻豆| 美女在线视频一区| 欧美精品一区二| 成人免费av网站| 亚洲色图视频网| 欧美老女人在线| 国产一区免费电影| 亚洲婷婷国产精品电影人久久| 色哟哟国产精品| 日韩电影在线一区| 中文无字幕一区二区三区| 97久久久精品综合88久久| 丝袜亚洲另类欧美| 久久综合中文字幕| 91久久免费观看| 久久99精品一区二区三区| 中文字幕亚洲精品在线观看| 欧美日韩国产三级| 久久99久久99小草精品免视看| 国产精品日日摸夜夜摸av| 欧美日韩日日摸| 国产91在线观看丝袜| 亚洲国产美女搞黄色| 久久综合色婷婷| 在线观看区一区二| 国产999精品久久久久久绿帽| 亚洲一级二级在线| 欧美激情一区二区三区蜜桃视频| 欧洲中文字幕精品| 国产精品一二一区| 青青草97国产精品免费观看| 国产精品国产三级国产专播品爱网| 欧美日韩国产大片| 99久久精品免费看| 国产一区二区三区黄视频| 亚洲一区二区免费视频| 国产三级精品视频| 欧美一级高清大全免费观看| 日本韩国欧美三级| 成人激情小说乱人伦| 久久av资源网| 日韩精品视频网站| 一区二区三区精品视频在线| 国产精品伦一区二区三级视频| 欧美一级夜夜爽| 欧美网站一区二区| 91免费观看国产| 成人av资源在线| 国产suv精品一区二区三区 | 国产精品―色哟哟| 精品国精品国产| 91麻豆精品国产91久久久资源速度| 一本到一区二区三区| 成人精品视频一区二区三区 | 欧美精品xxxxbbbb| 不卡的看片网站| 国产**成人网毛片九色| 狠狠色丁香久久婷婷综合_中 | 亚洲一二三四区| 亚洲精品久久久久久国产精华液 | 精品久久免费看| 欧美一区三区二区| 欧美日韩国产精选| 欧美美女视频在线观看| 欧美日韩综合色| 欧美撒尿777hd撒尿| 欧美视频在线播放| 欧美日韩一本到| 欧美精品九九99久久| 91精品国产综合久久精品| 欧美日韩电影在线播放| 91精选在线观看| 欧美精品一区二区三区四区| 精品对白一区国产伦| 2022国产精品视频| 中文字幕av在线一区二区三区| 中文一区在线播放| 亚洲丝袜另类动漫二区| 亚洲一区在线视频| 人人狠狠综合久久亚洲| 久草在线在线精品观看| 国产99久久久国产精品潘金| 成人丝袜18视频在线观看| 97se亚洲国产综合自在线不卡| 在线观看91视频| 欧美一级久久久久久久大片| 久久久久国产精品免费免费搜索| 中文久久乱码一区二区| 亚洲欧美激情小说另类| 午夜精品国产更新| 蜜臀av一级做a爰片久久| 国产黄色成人av| 色综合久久久久综合体桃花网| 欧美午夜寂寞影院| 久久久久久久久97黄色工厂| 国产精品福利一区| 丝瓜av网站精品一区二区| 国产一本一道久久香蕉| 色综合久久88色综合天天免费| 欧美猛男男办公室激情| 久久一二三国产| 一区二区三区小说| 韩国三级在线一区| 欧美专区亚洲专区| 久久精品人人做人人综合| 一区二区三区在线视频观看58| 青青青伊人色综合久久| 99久久精品免费| 精品国产91亚洲一区二区三区婷婷| 亚洲欧洲日韩综合一区二区| 蜜臀99久久精品久久久久久软件| k8久久久一区二区三区| 日韩美一区二区三区| 亚洲欧洲精品天堂一级| 麻豆精品一区二区三区| 91行情网站电视在线观看高清版| 精品福利在线导航| 五月天丁香久久| 国产98色在线|日韩| 欧美一区二区三区精品| 亚洲日本一区二区| 国产一区二区三区在线观看免费 | 国产清纯白嫩初高生在线观看91| 亚洲国产aⅴ天堂久久| 不卡一卡二卡三乱码免费网站| 日韩欧美一级精品久久| 亚洲国产色一区| 91丨九色丨蝌蚪丨老版| 欧美国产丝袜视频| 国产精品一区免费在线观看| 日韩一区二区三区电影在线观看 | 亚洲人成网站精品片在线观看| 久久精品国产澳门| 51精品视频一区二区三区| 一区二区理论电影在线观看| 粉嫩一区二区三区性色av| 精品国产成人系列| 麻豆精品视频在线观看| 4438x亚洲最大成人网| 亚洲国产精品一区二区www| 91蜜桃视频在线| 亚洲毛片av在线| www.日韩精品| 成人免费在线播放视频| 成人美女视频在线观看18| 国产日韩欧美在线一区| 国产精品中文有码| 欧美激情一区二区三区在线| 国产不卡在线播放| 欧美激情一区二区三区全黄 | 91 com成人网| 日韩电影免费在线| 91精品国产综合久久婷婷香蕉 | 日韩视频在线你懂得| 青青草精品视频|