Backendless Support
 
Answered

How to check if user password is correct?

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?

Leave a Comment

Comments (2)

photo
1

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

  1. class UserSecurity {
  2. /**
  3. * @param {String} userIdentity
  4. * @param {String} userPassword
  5. * @returns {Boolean}
  6. */
  7. isUserPasswordValid(userIdentity, userPassword) {
  8. const onLogin = () => {
  9. Backendless.UserService.logout()
  10. return true
  11. }
  12. return Backendless.UserService
  13. .login(userIdentity, userPassword)
  14. .then(onLogin, () => false)
  15. }
  16. }
  17. Backendless.enablePromises();
  18. 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

photo
1

Custom event handler also should work

  1. //server code
  2. Backendless.enablePromises();
  3. Backendless.ServerCode.customEvent('validatePassword', function(req) {
  4. return Backendless.UserService.login(req.args.login, req.args.password).then(
  5. () => true,
  6. () => false
  7. )
  8. });

  1. //client code
  2. Backendless.enablePromises();
  3. function validatePassword(login, password) {
  4. return Backendless.Events.dispatch('validatePassword', { login, password });
  5. }