Re: Password retrieval app
al.softdev@gmail.com wrote:
Hello,
I would like to create an online app where if the user (has account on
AD) has forgotten the password, can reset the password and that will
send a link to their email address to reset this temporary password.
This is almost similar to the password reset emails that we receive
from most of the online sites now.
Can someone guide me where I need to start? Anywhere from links to
ideas would be helpful
You need to use JNDI to access the ADS LDAP database, however
setting/resetting a password in ADS is only allowed through a SSL
connection. That is just something that it enforces so you can't get
around it (at least in this case they have high security).
Here is some of the code I use to do the password preparation and actual
modification work:
public byte[] processPassword(String pass) {
String newQuotedPassword = "\"" + pass + "\"";
try {
return newQuotedPassword.getBytes("UTF-16LE");
} catch (UnsupportedEncodingException Ex) {
LDAPMgr.mesgBar.setText(" Error encoding
password to unicode: " + Ex.getMessage(),
AlertStatus.ERROR);
return null;
}
}
public void setPassword(String dn, String pass) throws Exception {
ModificationItem[] mods = new ModificationItem[1];
byte[] newUnicodePassword = processPassword(pass);
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute("unicodePwd", newUnicodePassword));
ctx.modifyAttributes(new LdapName(dn), mods);
}
You will need to setup your InitialLdapContext object by authenticating
as some type of administrative user which will be used to set the user's
password on the user's behalf (an SSL cert. must be created for that
user so the SSL handshake can be made).
If you need further help let me know. I've created an LDAP application
that allows various operations to be performed to ADS as well as other
directory servers so I know the pitfalls you may run into.