How to know account exist on IM server?

Hi Guys,

How can i know if account already exists on IM server?

Thanks,

Wei

Hi Wei,

If you try to create an account using AccountManager#createAccount and the account already exists an XMPPException will be thrown, catch the exception, get the XMPPError from the exception, and then get the code from the error, if the code equals 409 then the account already exists. Here’'s what the code would look like:

try {
   XMPPConnection con = new XMPPConnection("myserver");
   con.connect();
   con.getAccountManager().createAccount("username", "password");
}
catch (XMPPException e) {
   if (e.getXMPPError().getCode() == 409) {
      System.out.println("account already exists...");
   }
}

Hope that helps,

Ryan

Is there any way of finding this information without trying to create an account?

I have a situation where I would like to detect that an account has been removed, so that the application in question can reconfígure itself and not try to login anymore.

The XMPPException doesnt have an XMPPError object to check when the account is missing, all I get is a message “SASL Authentication failed”.

Thanks for any help on this matter!

//Peter

Most systems don’'t differentiate, since it would allow hacking attempts (first try to find a login, then try to guess its password). Esp when considering SPIM (SPAM over IM), this would become a huge problem.

OK I can understand that, but since you can test the existance of an account by trying to create it, what’'s the difference?

//Peter

A bot creating a million accounts would probably be noticed, a million invalid logins would not.

Hi Peter,

Most XMPP servers and Smack have support for XEP-0055 so would it work to have an account that was in charge of searching to see if the account you want to create already exists?

Cheers,

Ryan

That would require you to log in to another account first, though.

Correct, that’'s why I asked if “…it work to have an account that was in charge of searching…?”.