• 카테고리
    • 전체 글

    • 카테고리1
    • 카테고리2
    • 카테고리3
    • 카테고리4
  • 태그
  • 방명록

사용자 암호 관리

기술자료/.NET 2012. 9. 12. 09:51

원본 : http://msdn.microsoft.com/ko-kr/library/ms180915(VS.80).aspx

(즐겨찾기에 있는 정보로 링크 변경이나, 사이트 변경에 따라 정보가 유실될 것 같아 홈페이지에 등록합니다. 아래의 문건의 권리는 모두 Microsoft 에 귀속됩니다.)


이 항목에는 사용자 암호 관리에 대한 정보 및 코드 예가 들어 있습니다.

다음 C# 코드 예에서는 IADsUser::SetPasswordadsi.iadsuser_setpassword 메서드를 호출하여 사용자 암호를 설정하는 방법을 보여 줍니다. IADsUser::SetPassword에 대한 자세한 내용은 MSDN Library(http://msdn.microsoft.com/library)의 "IADsUser::SetPassword"를 참조하십시오.

 
usr.Invoke("SetPassword", SecurelyStoredPassword);

다음 C# 코드 예에서는 IADsUser::ChangePasswordadsi.iadsuser_changepassword 메서드를 호출하여 사용자 암호를 변경하는 방법을 보여 줍니다. IADsUser::ChangePassword에 대한 자세한 내용은 MSDN Library(http://msdn.microsoft.com/library)의 "IADsUser::ChangePassword"를 참조하십시오.

 
usr.Invoke("ChangePassword", OldSecurelyStoredPassword, NewSecurelyStoredPassword);

다음 C# 코드 예에서는 다음 로그온 시 사용자 암호를 변경할 수 있도록 설정하는 방법을 보여 줍니다. 이 경우 pwdLastSetadschema.a_pwdlastset 속성을 off(-1)로 설정합니다. adschema pwdLastSet 특성에 대한 자세한 내용은 MSDN Library(http://msdn.microsoft.com/library)의 "pwdLastSet" 또는 "Pwd-Last-Set attribute"를 참조하십시오.

 
usr.Properties["pwdLastSet"].Value = -1; // To turn on, set this value to 0.
usr.CommitChanges();

 

다음 C# 코드 예에서는 암호를 변경하는 사용자 권한을 거부하도록 ACE를 설정하는 기능을 보여 줍니다. 이 경우 ntSecurityDescriptor 속성을 가져올 수 있도록 IADsSecurityDescriptor에 액세스하는 데 ADSI 액세스에 COM 상호 운용성 사용를 사용합니다. 그런 다음 IADsAccessControlList를 사용하여 보안 설명자의 DACL을 가져오고 IADsAccessControlEntry를 사용하여 AceType, AceFlags, Trustee, Flags, ObjectType 및 AccessMask 속성을 가져옵니다. AceType 플래그는 ADS_ACETYPE_ENUM에 정의되어 있습니다. AceFlags는 ADS_FLAGTYPE_ENUM에 정의되어 있습니다. AccessMask 플래그는 ADS_RIGHTS_ENUM에 정의되어 있습니다.

 
using System;
using System.DirectoryServices;
using ActiveDs;

static void DenyChangePassword(DirectoryEntry User)
{

	const string PASSWORD_GUID = "{ab721a53-1e2f-11d0-9819-00aa0040529b}";
	const int ADS_UF_PASSWORD_EXPIRED=0x800000;
	const int ADS_UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION=0x1000000;

	string[] trustees = new string[]{@"NT AUTHORITY\SELF","EVERYONE"};
	

	ActiveDs.IADsSecurityDescriptor sd = (ActiveDs.IADsSecurityDescriptor)

	User.Properties["ntSecurityDescriptor"].Value;

	ActiveDs.IADsAccessControlList acl = (ActiveDs.IADsAccessControlList) sd.DiscretionaryAcl;

	ActiveDs.IADsAccessControlEntry ace = new ActiveDs.AccessControlEntry();

	foreach(string trustee in trustees)
	{
		ace.Trustee = trustee;
		ace.AceFlags = 0;
		ace.AceType = (int)ActiveDs.ADS_ACETYPE_ENUM.ADS_ACETYPE_ACCESS_DENIED_OBJECT;
		ace.Flags = (int)ActiveDs.ADS_FLAGTYPE_ENUM.ADS_FLAG_OBJECT_TYPE_PRESENT;
		ace.ObjectType = PASSWORD_GUID;
		ace.AccessMask = (int)ActiveDs.ADS_RIGHTS_ENUM.ADS_RIGHT_DS_CONTROL_ACCESS;
		acl.AddAce(ace);
	}

	sd.DiscretionaryAcl = acl;
	User.Properties["ntSecurityDescriptor"].Value = sd;
	User.CommitChanges();
}

다음 C# 예에서는 암호를 변경하는 사용자 권한을 거부하도록 ACE를 설정하는 기능을 보여 줍니다. 이 예에서는 .NET Framework 2.0에서 사용할 수 있는 관리되는 ACL 기능을 사용합니다.

using System;
using System.DirectoryServices;
using System.Security.Principal;
using System.Security.AccessControl;

static void DenyChangePassword(DirectoryEntry user)
{
    // Create a Guid that identifies the Change Password right.
    Guid changePasswordGuid = 
        new Guid("{AB721A53-1E2F-11D0-9819-00AA0040529B}");

    // Get the ActiveDirectorySecurity for the user.
    ActiveDirectorySecurity userSecurity = user.ObjectSecurity;

    // Create a SecurityIdentifier object for "everyone".
    SecurityIdentifier everyoneSid = 
        new SecurityIdentifier(WellKnownSidType.WorldSid, null);

    // Create a SecurityIdentifier object for "self".
    SecurityIdentifier selfSid = 
        new SecurityIdentifier(WellKnownSidType.SelfSid, null);

    // Create an access rule to allow everyone the change password 
    // right. 
    // This is used to remove any existing access rules.
    ActiveDirectoryAccessRule allowEveryone = 
        new ActiveDirectoryAccessRule(
            everyoneSid,
            ActiveDirectoryRights.ExtendedRight, 
            AccessControlType.Allow, 
            changePasswordGuid);

    // Create an access rule to deny everyone the change password right.
    ActiveDirectoryAccessRule denyEveryone =
        new ActiveDirectoryAccessRule(
            everyoneSid,
            ActiveDirectoryRights.ExtendedRight,
            AccessControlType.Deny,
            changePasswordGuid);

    // Create an access rule to allow self the change password right.
    // This is used to remove any existing access rules.
    ActiveDirectoryAccessRule allowSelf =
        new ActiveDirectoryAccessRule(
            selfSid,
            ActiveDirectoryRights.ExtendedRight,
            AccessControlType.Allow,
            changePasswordGuid);

    // Create an access rule to deny self the change password right.
    ActiveDirectoryAccessRule denySelf =
        new ActiveDirectoryAccessRule(
            selfSid,
            ActiveDirectoryRights.ExtendedRight,
            AccessControlType.Deny,
            changePasswordGuid);

    // Remove any existing rule that gives "everyone" the change 
    // password right.
    userSecurity.RemoveAccessRuleSpecific(allowEveryone);

    // Add a new access rule to deny "everyone" the change password 
    // right.
    userSecurity.AddAccessRule(denyEveryone);

    // Remove any existing rule that gives "self" the change password 
    // right.
    userSecurity.RemoveAccessRuleSpecific(allowSelf);

    // Add a new access rule to deny "self" the change password right.
    userSecurity.AddAccessRule(denySelf);

    // Commit the changes.
    user.CommitChanges();
}

다음 코드 예에서는 암호가 만료되지 않도록 설정하는 방법을 보여 줍니다. 이 경우 ADS_USER_FLAG_ENUM에 정의되어 있는 ADS_UF_DONT_EXPIRE_PASSWD 플래그를 설정할 수 있도록 userAccountControl 속성에 액세스하기 위해 Properties 메서드를 사용합니다.

using System;
using System.DirectoryServices;
using ActiveDs;

static void DontExpirePassword(DirectoryEntry User)
{
    int val;
    const int ADS_UF_DONT_EXPIRE_PASSWD =0x10000;
    val = (int) User.Properties["userAccountControl"].Value;
    User.Properties["userAccountControl"].Value = val | 
        ADS_UF_DONT_EXPIRE_PASSWD;
    User.CommitChanges();
}


728x90
블로그 이미지

하인도1

[하인드/하인도/인도짱 의 홈페이지] 저만의 공간입니다. 다양한 소재들을 나열하는 아주 단순 무식한 홈페이지 입니다. 다양한 문서 자료도 있겠지만, 저의 푸념들도 있답니다.

250x250

블로그 내에 소스 코드 삽입 이사온 기념 스킨도... RSS 전문 기능 비활성화 관련. 스킨 바꾸어 보았습니다. 서버 파일 정리 좀 했습니다.

«   2025/06   »
일 월 화 수 목 금 토
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30

좀 블로그 2010 매뉴얼 협업 불만 오류 Google Apps Engine me2photo me2dayzm 개발환경 MOSS 2007 인터파크 java me2sms Buscuit Visual Studio 비스킷 e-book Azure 수 WSS SharePoint windows twi2me Tutorial moss 것 친구 지름신

  • Total :
  • Today :
  • Yesterday :

Copyright © 2015-2025 Socialdev. All Rights Reserved.

Copyright © 2015-2025 Socialdev. All Rights Reserved.

티스토리툴바