Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register a new user on XMPP using (a)Smack library

I have set up a xmpp server and android client using the great post here... I have some pre defined users set up in the xmpp server and i could login with those credentials.

Now, from my app i want to register as new users to the xmpp server through the android client. Can anyone please suggest me how to attain this... Any help will be grately appreciated...!!!

like image 513
Rahul Kalidindi Avatar asked Dec 18 '10 05:12

Rahul Kalidindi


3 Answers

Smack has InBand registration functionality that can be used via the AccountManager class. Note that not every server has this feature implemented/enabled.

like image 70
Flow Avatar answered Nov 14 '22 00:11

Flow


Maybe I am late, but if you are using latest smack-android:4.1.0, you can try below code for creating XMPPTCPConnectionConfiguration's connection object and register a user:

// Creating a connection
XMPPTCPConnectionConfiguration connConfig =
        XMPPTCPConnectionConfiguration.builder()
                .setHost("myHost.com")  // Name of your Host
                .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
                .setPort(5222)          // Your Port for accepting c2s connection
                .setDebuggerEnabled(true)
                .setServiceName("myServiceName")
                .build();
AbstractXMPPConnection connection = new XMPPTCPConnection(connConfig);

try {
    // connecting...
    connection.connect();
    Log.i("TAG", "Connected to " + connection.getHost());

    // Registering the user
    AccountManager accountManager = AccountManager.getInstance(connection);
    accountManager.sensitiveOperationOverInsecureConnection(true);
    accountManager.createAccount(username, password);   // Skipping optional fields like email, first name, last name, etc..
} catch (SmackException | IOException | XMPPException e) {
    Log.e("TAG", e.getMessage());
    xmppClient.setConnection(null);
}
like image 43
Meet Vora Avatar answered Nov 14 '22 01:11

Meet Vora


Just elaborating on what Flow has posted. AccountManager class has all the ingredients for maintaining user accounts in XMPP

Assume you have a connection object created.

AccountManager accountManager=new AccountManager(connection);
try {
    accountManager.createAccount("username", "password");
} catch (XMPPException e1) {
    Log.d(e1.getMessage(), e1);
}
like image 4
Prakash Avatar answered Nov 14 '22 00:11

Prakash