Backendless Support
 

Changing a user password via API (if a user can login)

There are several ways that are offered by Backendless Service Platform for changing a user's password. It can be accomplished either using Backendless console or via API.

This topic highlights one of Backendless options to change a user password using API - in particular, a scenario when a user CAN login. 

A different scenario is possible when a user CANNOT login for the reason that he/she forgot the password. This is covered by the topic " ".

So changing a user password via Backendless API if a user CAN login will be as follows. 

Asynchronous API sample (Android and Plain Java):
Backendless.UserService.login( "spidey@backendless.com", "greeng0blin", new AsyncCallback<BackendlessUser>()
{
 @Override
 public void handleResponse( BackendlessUser user )
 {
 user.setPassword( "MyNewPassword" );
 Backendless.Data.of( BackendlessUser.class ).save( user, new AsyncCallback<BackendlessUser>()
 {
 @Override
 public void handleResponse( BackendlessUser backendlessUser )
 {
 System.out.println( "User password has been changed" );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
 }
 } );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
 }
} );
Synchronous API sample (Plain Java only):
BackendlessUser user = Backendless.UserService.login( "spidey@backendless.com", "myNewPassword" );
user.setPassword( "myNewPassword1" );
Backendless.Data.of( BackendlessUser.class ).save( user );

NOTICE: the sample shows user login first. This is required as the user identify must be established for the subsequent password update call to go through.

 Review related topic:

Is article helpful?