Skip to content

Backendless Login API

Registered users can login using the API described below. The login operation requires two properties: one marked asuser identity and the second is password. Backendless automatically assigns the "AuthenticatedUser" role to all successfully logged in users. The role can be used to differentiate access to various resources (data in the database, files, messaging channels) between authenticated users and guests.

- (void)loginWithIdentity:(NSString * _Nonnull)identity password:(NSString * _Nonnull)password responseHandler:^(BackendlessUser * _Nonnull)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func login(identity: String, password: String, responseHandler: ((BackendlessUser) -> Void)!, errorHandler: ((Fault) -> Void)!)


Argument                Description
identity a value for a property marked as identity.
password user's password

Return value

The login API returns a BackendlessUser object representing the logged in user. The object has the values for all the properties stored in Backendless database including those for which the "auto-load" option is enabled.


The following errors may occur during the Login API call. See the Error Handling section for details on how to retrieve the error code when the server returns an error.

Error Code
Version is disabled or provided wrong application info (application id or secret key)
Login has been disabled for the user account.
Missing login settings, possibly invalid application id or version.
User cannot login because Multiple Logins disabled and there is a logged in user for the account.
Invalid login or password.
Either login or password is an empty string value.
User logins are disabled for the version of the application.
Account locked out due to too many failed logins.
One of the required parameters (application id, version, login or password) is null
Multiple login limit for the same user account has been reached.
Property value exceeds the length limit
[Backendless.shared.userService loginWithIdentity:@"" password:@"iAmWatchingU" responseHandler:^(BackendlessUser *loggedInUser) {
    NSLog(@"User has been logged in");
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
Backendless.shared.userService.login(identity: "", password: "iAmWatchingU", responseHandler: { loggedInUser in
    print("User has been logged in")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")

Remembering User Login

It is a frequent requirement for the applications to store user's login so next time application starts, the user is not required to login. The user interface for this scenario is typically a "Remember me" checkbox.

There is a stayLoggedInproperty in user service that must be set after application has been initialized with the initApp call before the login API is used:


Backendless.shared.userService.stayLoggedIn = YES;
Backendless.shared.userService.stayLoggedIn = true

Additionally this property indicates if the current state of the system is set to allow persistent logins:

BOOL isStayLoggedIn = Backendless.shared.userService.stayLoggedIn;
let isStayLoggedIn = Backendless.shared.userService.stayLoggedIn

If the persistent logins are enabled, the property returns Yes/true, otherwise No/false.

Validating User Login

The login operation provides a way to persist the user-token on the client side so it can be used when the application is restarted. This helps in streamlining the user experience since the user of the application does not need to login again. However, when the application restarts, it needs to check if the underlying user token, and hence the user session are still valid. This can be accomplished with the API below:

-(void)isValidUserTokenWithResponseHandler:^(BOOL)responseHandler errorHandler:^(Fault * _Nonnull)errorHandler;
func isValidUserToken(responseHandler: ((Bool) -> Void)!, errorHandler: ((Fault) -> Void)!)

Return value

The server returns a boolean value of true if token is valid, false otherwise.


[Backendless.shared.userService isValidUserTokenWithResponseHandler:^(BOOL isValid) {
    NSLog(@"User token is valid: %i", isValid);
} errorHandler:^(Fault *fault) {
    NSLog(@"Error: %@", fault.message);
Backendless.shared.userService.isValidUserToken(responseHandler: { isValid in
    print("User token is valid: \(isValid)")
}, errorHandler: { fault in
    print("Error: \(fault.message ?? "")")