Support Topics Documentation Slack YouTube Blog

How to check if user password is correct?


(Avery Choke) #1

It doesn’t seems to be any API in Backendless to check the validity of password aside from login and reset password. I would like to allow a logged in user to change his email or name by having him to enter the password of the account. If the password is correct then only proceed with the update. Is there any method to do so?


(Vladimir Upirov) #2

Hey Avery

I’m sorry but now we don`t have this functionality.
But I can propose to you a some workaround.
You can do that via BusinessLogic through APIService
https://backendless.com/documentation/business-logic/js/apieng_rest_routes.htm

class UserSecurity {


  /**
   * @param {String} userIdentity
   * @param {String} userPassword
   * @returns {Boolean}
   */
  isUserPasswordValid(userIdentity, userPassword) {
    const onLogin = () => { 
    	Backendless.UserService.logout()
        return true
    }


    return Backendless.UserService
    			.login(userIdentity, userPassword)
    			.then(onLogin, () => false)
  } 
}
  
Backendless.enablePromises();


Backendless.ServerCode.addService(UserSecurity);


And the where you want you can call the apiService with (userIdentity, userPass) params, and check if user input correct password
https://backendless.com/documentation/business-logic/js/apieng_rest_routes.htm

Regards, Vlad


(Vitaly Vengrov) #3

Custom event handler also should work

//server code
Backendless.enablePromises();
Backendless.ServerCode.customEvent('validatePassword', function(req) {
return Backendless.UserService.login(req.args.login, req.args.password).then(
() => true,
() => false
)
});
//client code
Backendless.enablePromises();
function validatePassword(login, password) {
return Backendless.Events.dispatch('validatePassword', { login, password });	
}