
LDAP_exop_passwd는 LDAP 프로토콜의 확장 기능 중 하나로, 사용자 암호를 변경하는 기능을 제공합니다.
인증 절차는 다음과 같습니다.
1. 클라이언트가 LDAP 서버에 연결합니다.
2. 클라이언트는 LDAP 서버에 암호 변경을 요청합니다.
3. LDAP 서버는 클라이언트의 인증을 확인합니다. 인증은 일반적으로 사용자 이름과 현재 암호를 사용합니다.
4. 인증이 성공하면 LDAP 서버는 새로운 암호를 저장합니다.
LDAP_exop_passwd를 사용하여 암호를 변경하는 예제 코드는 다음과 같습니다.
C# 예제:
#hostingforum.kr
csharp
using System;
using System.DirectoryServices.Protocols;
class LdapPasswordChange
{
static void Main(string[] args)
{
// LDAP 서버의 주소
string ldapServer = "ldap://localhost:389";
// 사용자 이름
string username = "johnDoe";
// 현재 암호
string currentPassword = "oldPassword";
// 새로운 암호
string newPassword = "newPassword";
// LDAP 서버에 연결
using (LdapConnection connection = new LdapConnection(ldapServer))
{
// 인증
connection.Bind(new NetworkCredential(username, currentPassword));
// 암호 변경
ModifyRequest modifyRequest = new ModifyRequest("cn=" + username, new[] { new ModificationChangeItem("userPassword", newPassword) });
connection.SendRequest(modifyRequest);
}
}
}
Java 예제:
#hostingforum.kr
java
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
import java.util.Hashtable;
public class LdapPasswordChange
{
public static void main(String[] args)
{
// LDAP 서버의 주소
String ldapServer = "ldap://localhost:389";
// 사용자 이름
String username = "johnDoe";
// 현재 암호
String currentPassword = "oldPassword";
// 새로운 암호
String newPassword = "newPassword";
// LDAP 서버에 연결
Hashtable env = new Hashtable<>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapServer);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, currentPassword);
try
{
DirContext ctx = new InitialDirContext(env);
// 암호 변경
ModificationItem[] mods = new ModificationItem[1];
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("userPassword", newPassword));
ctx.modifyAttributes("cn=" + username, mods);
ctx.close();
}
catch (NamingException e)
{
System.out.println("Error: " + e.getMessage());
}
}
}
2025-03-08 03:38