Check if username exists before registration

When doing in band registration, how can i check if the user already exists?

Should i just be attempting to login with the supplied username / password, and check for an exception?

1 Like

So i tried just checking for an exception, when creating on account, using something like this:

if(e.getXMPPError().getCondition() == XMPPError.Condition.conflict) {}

but then when trying to create a new account after, i get locked out for 10 mins or so

with a “not_acceptable - wait” error

So this doesn’t seem like the correct way to do it.

Are you using openfire?

Ive been searching for the same issue, and i uploaded a plugin for it name Presence Service , using http request in android i can get if the user exists or not, this is my http request, pe=xml

and i can get this response in xml: if user exists


and when user doesnt exist

maybe that can help, but if u find the right solution please tell me

So this doesn’t seem like the correct way to do it.

No, it’s the correct way (See XEP-77 Example 6). The server is just returning the wrong response in this case (maybe in an attempt to prevent brute forcing the usernames).

I found this solution not adequate, i dont know what is the UserSearchManager class for. i thought this class was for that purpose.

Maybe someone has the right solution. Meanwhile ill be using the previous method

Ive found the right solution. But you have to be logged with an account to search for users.

Create and login with any account in smack

  1. Be sure you have the search plugin in y our openfire service.

Go to Search Service Properties on Server configuration

Click on Clients will be able to search for users to enable it

On search scope click on anyone

  1. In Android smack (4.2.0):

    conn.login(“searcher”, “searcher”);

    conn.sendStanza(new Presence(Presence.Type.available));

UserSearchManager userSearchManager = new UserSearchManager(conn);

DomainBareJid searchService = JidCreate.domainBareFrom(“search.”);

Form searchForm = userSearchManager.getSearchForm(searchService);

Form answerForm = searchForm.createAnswerForm();

answerForm.setAnswer(“Username”, true);

answerForm.setAnswer(“search”, username);

ReportedData data = userSearchManager.getSearchResults(answerForm,searchService);

 if(data.getRows() != null) {

List<ReportedData.Row> rows = data.getRows();

Iterator<ReportedData.Row> it = rows.iterator();

if (it.hasNext()) {

//user exists

} else {

             //user doesnt exists



//then logout, and create or login if that account exists or not

Now we have found two ways to do it, i think the best way is the first i mentioned even if we are not using smack, but you dont have to be logged

to do this.

Anyway im openmind for other solutions, hope we can find some more.