Blog

How to Change a User’s Password via API If User Cannot Login (Temp Password)

by on September 1, 2019

In other articles on user management, we have discussed changing a user’s password as the administrator or via API (if the user can log in). There is also a scenario where a user needs to change their password, but they can’t log in because they forgot their password. In this case, Backendless provides a simple API that delivers a temporary password to the user’s email address.

The email message can be customized by editing the template for the ‘restore password’ event. Let’s take a look at the code for changing the user’s password via API.

Asynchronous API sample:

Backendless.UserService.restorePassword( "spidey@backendless.com", new AsyncCallback<Void>()
{
    @Override
    public void handleResponse( Void aVoid )
    {
        System.out.println( "Temporary password has been emailed to the user" );
    }
    @Override
    public void handleFault( BackendlessFault backendlessFault )
    {
        System.out.println( "Server reported an error - " + backendlessFault.getMessage() );
    }
} );

Synchronous API sample:

Backendless.UserService.restorePassword( "spidey@backendless.com" );
System.out.println( "A temporary password has been emailed to the user" );

Leave a Reply